From:             
Operating system: Irrelevant
PHP version:      5.3.5
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Closures have invalid context

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..

-- 
Edit bug report at http://bugs.php.net/bug.php?id=54202&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54202&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54202&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54202&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54202&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54202&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54202&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54202&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54202&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54202&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54202&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54202&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54202&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54202&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54202&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54202&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54202&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54202&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54202&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54202&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54202&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54202&r=mysqlcfg

Reply via email to