Tutorial :How to tell when a PHP Fatal Error is really a veiled Syntax Error, and when do they happen?


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.


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?


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.


These are "compile errors", thrown by the compiler when it encounters a syntactically valid but "uncompilable" construct. Go to http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_compile.c and search for "E_COMPILE_ERROR" - there are quite a few.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »