Bug #76206 [NEW]: Arrays in objects using splat aren't passed by reference in a dynamic call
| From: | d28b312d at opayq dot com | Date: | Tue, 10 Apr 2018 18:10:40 +0000 |
| Subject: | Bug #76206 [NEW]: Arrays in objects using splat aren't passed by reference in a dynamic call | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-214693@lists.php.net to get a copy of this message | ||
From: d28b312d at opayq dot com
Operating system: *
PHP version: Irrelevant
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Arrays in objects using splat aren't passed by reference in a dynamic call
Description:
------------
If you have an object with an array parameter, and you try to pass that
to a closure which accepts parameters by reference, the parameters
aren't taken in by reference and instead by value.
Modifying the below script to use
$foo instead of $this->foo in both
cases will work, but using the instance assigned to an object parameter
seems to pass the values by value without an error, instead of by
reference like the function implies.
Note:
If you try to use call_user_func_array it throws a message saying it's
passing by value to a reference expecting function which is at least
better than showing nothing and just treating as if it's a value (but
both are wrong!).
`PHP Warning: Parameter 1 to {closure}() expected to be a reference,
value given`
Test script:
---------------
<?php
class Foo
{
private $foo;
public function call(Closure $cl, $foo)
{
$this->foo = $foo;
$cl(...$this->foo);
var_dump($this->foo);
return $cl(...$this->foo);
}
}
$f = new Foo;
echo $f->call(function(&$i){return ++$i;}, [0]);
Expected result:
----------------
/tmp/classtest.php:11:
array(1) {
[0] =>
int(1)
}
2
Actual result:
--------------
/tmp/classtest.php:11:
array(1) {
[0] =>
int(0)
}
1
--
Edit bug report at https://bugs.php.net/bug.php?id=76206&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76206&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76206&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76206&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76206&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76206&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76206&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76206&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76206&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76206&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76206&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76206&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76206&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76206&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76206&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76206&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76206&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76206&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76206&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76206&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76206&r=mysqlcfg