|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-03-09 16:38 UTC] cataphract@php.net
-Status: Open
+Status: Bogus
[2011-03-09 16:38 UTC] cataphract@php.net
[2011-03-09 17:03 UTC] landeholm at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 11:00:02 2025 UTC |
Description: ------------ It doesn't make sense that closures declared inside methods are run with global context instead of the same context as the method. This is incredibly annoying as it there are no way to reference private/protected functions in closures. It's not possible to acquire a reference to the private/protected functions and pass them to the closure either so you're locked out from a developers perspective. See test script. The fix should be simple. Just inherit the access-context when closures are declared... Test script: --------------- class Foo { private function bar($a, $b) { return $a + $b; } public function baz($c) { $biz_fn = function($c) { return Foo::bar(5, 4) - $c; }; return $biz_fn($c); } } $foo = new Foo(); echo $foo->baz(3); Expected result: ---------------- "6" Actual result: -------------- Fatal error: Call to private method Foo::bar() from context '' in..