From: Operating system: Win7 PHP version: 5.3.6 Package: Class/Object related Bug Type: Bug Bug description:inconsistent error-handling for $this
Description: ------------ $this is not generally allowed outside an object context, but sometimes it is. I discovered this while trying to write a cheeky little base-class that would allow you to decorate objects with new methods, at run-time. I would have gotten away with it, too - and I still could of course, only I would have to break from the convention of $this, and naming the context-object something else, which kind of sucks. Test script: --------------- <?php $foo = function($this) { var_dump($this); // this will work! }; $foo('bar'); // now an object: class Test { public $foo = 'bar'; } $test = new Test; // and another closure: $ouch = function($this) { var_dump($this->bar); // this will blow up }; $ouch($test); Expected result: ---------------- The two examples should either fail consistently, or succeed consistently. >From my point of view, why should I not be allowed to have a local variable named $this if I wanted to? There's nothing special or magical about this variable, besides the fact that it gets automatically assigned on call. Actual result: -------------- The second example fails. -- Edit bug report at http://bugs.php.net/bug.php?id=55038&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=55038&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=55038&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=55038&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=55038&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=55038&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=55038&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=55038&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=55038&r=needscript Try newer version: http://bugs.php.net/fix.php?id=55038&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=55038&r=support Expected behavior: http://bugs.php.net/fix.php?id=55038&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=55038&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=55038&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=55038&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=55038&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=55038&r=dst IIS Stability: http://bugs.php.net/fix.php?id=55038&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=55038&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=55038&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=55038&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=55038&r=mysqlcfg