views:

31

answers:

1

Considering the following PHP class:

class someObject {
    public function broken(){
        return isset($this->something()) ? 'worked' : 'didnt';
    }

    public function something(){
        return true;
    }

    public function notBroken(){
        print('worked');
    }
}

Let's say I now do:

$obj= new someObject();
$obj->broken();

Considering you can't pass a function call to isset(), (it's by-reference), I expect this to fail with a fatal error: PHP Fatal error: Can't use method return value in write context This is fine, and expected.

However, let's say I now do:

$obj= new someObject();
$obj->notBroken();

Considering I'm not hitting the broken() anywhere in this execution, and the error in broken() is a Fatal Error (and not a Parse error), I wouldn't expect the normal output of "worked". FALSE! It still generates the Fatal Error.

Question:

Aside from just not writing code that has errors, are there any other errors that are not Parse Errors but still trigger a runtime error? I only know about: PHP Fatal error: Can't use method return value in write context. Is there any way to detect these errors? Is there a special name for this type of error?

A: 

The reason for this specific behaviour is probably that isset() is a language construct and not a normal function that gets interpreted at runtime. So it stands to reason this is kind of a parse error.

I have no deep insight in this though, and I don't know whether this class of errors has a specific name.

Pekka