#50418 [Opn->Bgs]: self in closures has no class scope

From: Date: Wed, 09 Dec 2009 08:37:28 +0000
Subject: #50418 [Opn->Bgs]: self in closures has no class scope
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-145562@lists.php.net to get a copy of this message
ID: 50418 Updated by: jani@php.net Reported By: crashrox at gmail dot com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Linux PHP Version: 5.3.1 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Of course __CLASS__ shows the current class you're "in". It's a constant, available in all scopes. Previous Comments: ------------------------------------------------------------------------ [2009-12-08 23:55:42] crashrox at gmail dot com Description: ------------ A closure within a static method loses self scope. When you print __CLASS__ within a closure it claims to belong to the class. But yet you cant access anything from that class. Reproduce code: --------------- class Test { public function do_something() { $func = function() { echo 'I belong to: ' . __CLASS__; return self::do_something_else(); }; return $func(); } public static function do_something_else() { return 'I did something else'; } } echo Test::do_something(); Expected result: ---------------- i belong to: Test i did something else Actual result: -------------- Test Fatal error: Cannot access self:: when no class scope is active in /home/jument/adam/jument/web/index.php on line 7 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50418&edit=1

« previous php.bugs (#145562) next »