Bug #75148 [NEW]: Changing array entry including &$this causes warning with call_user_func_array
| From: | robin at ambitionally dot com | Date: | Fri, 01 Sep 2017 21:54:33 +0000 |
| Subject: | Bug #75148 [NEW]: Changing array entry including &$this causes warning with call_user_func_array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-210912@lists.php.net to get a copy of this message | ||
From: robin at ambitionally dot com
Operating system: Windows, Linux
PHP version: 7.1.9
Package: Class/Object related
Bug Type: Bug
Bug description:Changing array entry including &$this causes warning with call_user_func_array
Description:
------------
When modifying an argument array that includes an entry for &$this, the
assignment operation seems to de-reference the &$this argument. As shown
in the test script, line 6 and line 8 are identical, and line 7 assigns
the same value to index [0] of the array.
The issue is specific to PHP 7.1 (I have tested with 7.1.8 and 7.1.9),
but it does not appear in PHP 7.0.
var_dump before and after the assignment operation has the same
printout. There is a difference in var_dump output between PHP 7.0 and
7.1. In 7.1, the var_dump output is missing the "&" for array entry [1],
while the "&" symbol is present in PHP 7.0.
This issue causes problems for WordPress sites, as it uses similar logic
when running filters (WP_Hook::apply_filters).
Test script:
---------------
<?php
function test_call($first, &$a) {
echo '<div>here</div>';
}
function test_warning($args) {
call_user_func_array( 'test_call', $args ); // this line works
$args[ 0 ] = 1;
call_user_func_array( 'test_call', $args ); // this line causes error
}
class TestWarningClass{
function __construct() {
$args = array( 1, &$this );
test_warning($args);
}
}
$test = new TestWarningClass;
Expected result:
----------------
No warning. Two lines of "here" are printed.
Actual result:
--------------
Warning: Parameter 2 to test_call() expected to be a reference, value
given
--
Edit bug report at https://bugs.php.net/bug.php?id=75148&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75148&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75148&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75148&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75148&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75148&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75148&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75148&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75148&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75148&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75148&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75148&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75148&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75148&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75148&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75148&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75148&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75148&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75148&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75148&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75148&r=mysqlcfg