autoload somewhat broken? or do the docs need more info?

From: Date: Thu, 17 Jul 2008 09:50:02 +0000
Subject: autoload somewhat broken? or do the docs need more info?
Groups: php.internals 
Request: Send a blank email to internals+get-39041@lists.php.net to get a copy of this message
hello people, I believe there is something wrong (or inconsitent) with the way __autoload() behaves. at the least the current docs don't reflect what I'm seeing. 1. the docs state: "Exceptions thrown in __autoload function cannot be caught in the catch block and results in a fatal error." this is not exactly true, I can catch exception throw from __autoload() IF __autoload() was triggered via call_user_func*(), class_exists() & is_callable() 2. if a user error handler is set with set_error_handler() any errors (at least upto and including E_WARNING) that occur in a function that triggers (e.g. call_user_func()) __autoload() will not be given to the error handler function (it never recieves a call) if the __autoload() it triggered throws an exception (that is not caught inside __autoload(). 3. I suspect that point 2. is the reason that in some real-world situations even Fatal Errors are not logged at (to screen or file, regardless of error_reporting/display_error settings), resulting in a blank screen and no idea as to the cause ... I have seen this happen repeatedly on different versions/machines/etc since php5 was in beta ... I have still not be able to reproduce the vanishing Fatal Errors in a simple test script ... that said on all occasions where nothing was logged for such Fatal Errors (which in my case are always the result of a class that cannot be found) I could run the same script via a debugger which then always did show the Fatal Error message ... why would running the script via a debugger show [Fatal Error] output in the browser window where as running the script normally [in the browser] results in no output whatsoever? Anyway I don't really know if anything is wrong, whether the docs need updating, or whether someone should really look at the situation. I have written a little 'test suite'[1] with which one can observe __autoload() behaviour in various configurations ... it comes with little shell script called 'runtests.sh': $ ./runtests.sh usage: ./runtests.sh <testset> [--set-err-handler] [--display-errors] [--gen-class] [--no-autoload|--no-throw [--spl-autoload]] <testset> must be one of: new new2 static class_exists call_user_func call_user_func_array is_callable OR all
      --set-err-handler       = define a user function to trap php errors.
      --display-errors        = sets php ini setting display_errors on.
      --no-autoload           = skip autoloader function definition.
      --no-throw              = tell the autoloader not to throw the exception.
      --spl-autoload          = use spl_autoload_register() instead of __autoload()
      --recurse-autoload      = trigger __autoload from within __autoload
      --gen-class             = to have autoload auto-generate the class (exception will still be thrown)
                                classes will have __construct(), __call() and __callstatic() methods
1. you may export an environment variable $PHP_TEST_BIN to control which php binary used to run the tests 2. errors logs are recreated on each run for each <testset> in ./logs/<testset>.log rgds, Jochem [1] http://iamjochem.com/autoload_behaviour_tests.zip

« previous php.internals (#39041) next »