From: php at davidstockton dot com Operating system: Centos 6 PHP version: 5.5.3 Package: Scripting Engine problem Bug Type: Bug Bug description:Closure executed via static autoload incorrectly marked as static
Description: ------------ If I load a class via a static autoloader which has executable code (including a closure) and then try to bind the closure to an object of the class, I get a warning and error: Warning: Cannot bind an instance to a static closure and Fatal error: Using $this when not in object context If I run the script directly (not via autoloader) everything works as expected. If I make the autoloader non-static, everything works as expected. Test script: --------------- Sample contains two files, a static autoloader which will load the class file and the class file which also contains executable code. If the autoloader is a plain function or a non-static method then the code works as expected. If the executable code is removed from the class file and placed into the autoloader file, everything works as expected. php Autoloader.php (bad behavior) php ClosureBug.php (correct behavior) https://gist.github.com/dstockto/6395158 Expected result: ---------------- 42 Actual result: -------------- Warning: Cannot bind an instance to a static closure in /vagrant/src/Bug/ClosureBug.php on line 9 Fatal error: Using $this when not in object context in /vagrant/src/Bug/ClosureBug.php on line 19 -- Edit bug report at https://bugs.php.net/bug.php?id=65598&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65598&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65598&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65598&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65598&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65598&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65598&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65598&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65598&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65598&r=support Expected behavior: https://bugs.php.net/fix.php?id=65598&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65598&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65598&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65598&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65598&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65598&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65598&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65598&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65598&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65598&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65598&r=mysqlcfg