Bug #68792 [NEW]: Can't declare closure using $this within static method (context)

From: Date: Sat, 10 Jan 2015 17:43:13 +0000
Subject: Bug #68792 [NEW]: Can't declare closure using $this within static method (context)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189868@lists.php.net to get a copy of this message
From: llmll at gmx dot de Operating system: any PHP version: 5.5.20 Package: Scripting Engine problem Bug Type: Bug Bug description:Can't declare closure using $this within static method (context) Description: ------------ The problem arises, when you try to declare a Closure (anonymous function) from within a static method. The compiler breaks on the $this keyword which must not occur in a static method. However, $this is only used in the closure body and should be ignored, therfore. Test script: --------------- class Test { public static function start() { $closure = function() { echo $this->foo; }; $object = new \StdClass; $object->foo = "Hello World"; $closure->bindTo($object)->__invoke(); } } Test::start(); Expected result: ---------------- should echo "Hello World" Actual result: -------------- Fatal error: Using $this when not in object context -- Edit bug report at https://bugs.php.net/bug.php?id=68792&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68792&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68792&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68792&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68792&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68792&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68792&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68792&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68792&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68792&r=support Expected behavior: https://bugs.php.net/fix.php?id=68792&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68792&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68792&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68792&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68792&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68792&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68792&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68792&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68792&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68792&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68792&r=mysqlcfg

« previous php.bugs (#189868) next »