CHAPTER 7 – TYPES OF ERRORS – Functions and Classes

Although PHP keeps executing after run- ning across an undefined variable or constant, it aborts whenever it encoun- ters an undefined function or class: <?php print "Yoda says:n"; undefined_this_function_is(); print "Do or do not, there is no try.n"; ?> The output is Yoda says: Fatal error: Call to undefined function: undefined_this_function_is() in test.php on line 4 The second print on line 5 was never executed because PHP exits with a fatal error when it tries to call the undefined function. The same thing happens with an undefined class: <?php print "Yoda says:n"; new undefined_class; print "Do or do not, there is no try.n"; ?> The output is Yoda says: Fatal error: Class 'undefined_class' not found in test.php on line 4 Classes have one exception. If there is a user-defined function called __autoload, it is called when PHP runs across an undefined class. If the class is defined after __autoload returns, the newly loaded class is used, and no fatal error occurs.

Post Comment
Login to post comments