Bug #72326 [Com]: Closure::call does not allow closure to accept arguments by reference
| From: | contact at jaborandi dot org dot ru | Date: | Fri, 03 Jun 2016 10:51:47 +0000 |
| Subject: | Bug #72326 [Com]: Closure::call does not allow closure to accept arguments by reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201422@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72326&edit=1
ID: 72326
Comment by: contact at jaborandi dot org dot ru
Reported by: contact at jaborandi dot org dot ru
Summary: Closure::call does not allow closure to accept
arguments by reference
Status: Open
Type: Bug
Package: Variables related
PHP Version: 7.0.7
Block user comment: N
Private report: N
New Comment:
Extra test code, to compare with cases when works:
$a = function($arg) { echo "\nok"; };
$aRef = function(&$arg) { echo "\nok"; };
$z = 1;
$a($z); // ok
$aRef($z); // ok
call_user_func($a, $z); // ok
call_user_func($aRef, $z); // ok
class MyContext {}
$a->call(new MyContext, $z); // ok
$aRef->call(new MyContext, $z); // WARNING ...
Expected:
ok
ok
ok
ok
ok
ok
Actual:
ok
ok
ok
ok
ok
Warning: Parameter 1 to MyContext::{closure}() expected to be a reference, value given in
C:\bin\php7.0.7\bug.php on line 17
Previous Comments:
------------------------------------------------------------------------
[2016-06-03 10:47:20] contact at jaborandi dot org dot ru
Description:
------------
calling Closure::call() method on anonymouse function that accepts arguments by reference triggers
Warning and doesn't execute the function
if same closure is called in regular way, or using call_user_func, or if it does not accept any
argument by reference, it is executed normally
tested in 7.0.7, as well as in 7.0.3, 7.0.4, 7.0.5, with the same result
(haven't tested call_user_func in 7.0.5 though, sandbox disabled it)
Test script:
---------------
$a = function(&$arg) { echo "ok"; };
$z = 1;
class MyContext {}
$a->call(new MyContext, $z);
Expected result:
----------------
ok
Actual result:
--------------
Warning: Parameter 1 to MyContext::{closure}() expected to be a reference, value given in
C:\bin\php7.0.7\bug.php on line 6
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72326&edit=1