Bug #66430 [NEW]: ReflectionFunction::invoke does not invoke closure with object scope
From: westie at typefish dot co dot uk
Operating system: All
PHP version: 5.5.7
Package: Reflection related
Bug Type: Bug
Bug description:ReflectionFunction::invoke does not invoke closure with object scope
Description:
------------
Whenever you try to invoke a closure using ReflectionFunction, the
object context that is bound to it is not carried across, therefore
execution fails.
This is broken for:
ReflectionFunction::invoke
ReflectionFunction::invokeArgs
The desired functionality can be obtained by:
Directly calling: $closure()
call_user_func($closure)
This happens when you ->bindTo a closure, or you get a closure for a
method using ReflectionMethod::getClosure().
Verified on PHP 5.4 latest dotdeb stable and 5.5 latest dotdeb stable.
Test script:
---------------
- http://ss.westie.sh/xpwa
Expected result:
----------------
outragebot@thor:~$ php ./bug.php
alpha.bravo: Valid representation
reflection of alpha.bravo: Valid representation
closure of alpha.bravo: Valid representation
call_user_func of closure: Valid representation
closure cl of c(alpha.bravo): Alpha
scope cl of c(alpha.bravo): Alpha
reflection of c(alpha.bravo): Valid representation
Actual result:
--------------
outragebot@thor:~$ php ./bug.php
alpha.bravo: Valid representation
reflection of alpha.bravo: Valid representation
closure of alpha.bravo: Valid representation
call_user_func of closure: Valid representation
closure cl of c(alpha.bravo): Alpha
scope cl of c(alpha.bravo): Alpha
reflection of c(alpha.bravo): PHP Fatal error: Using $this when not in
object context in /home/outragebot/bug.php on line 10
PHP Stack trace:
PHP 1. {main}() /home/outragebot/bug.php:0
PHP 2. ReflectionFunction->invoke() /home/outragebot/bug.php:32
PHP 3. Alpha::bravo() /home/outragebot/bug.php:32
--
Edit bug report at https://bugs.php.net/bug.php?id=66430&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66430&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66430&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66430&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66430&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66430&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66430&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66430&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66430&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66430&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66430&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66430&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66430&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66430&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66430&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66430&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66430&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66430&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66430&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66430&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66430&r=mysqlcfg
Thread (7 messages)
- westie at typefish dot co dot uk