|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-09 08:37 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 28 21:00:02 2025 UTC |
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