Bug #73751 [Opn->Nab]: 7.1.0 changed behaviour of &$this when used in callback
Edit report at https://bugs.php.net/bug.php?id=73751&edit=1
ID: 73751
Updated by: nikic@php.net
Reported by: jamesin dot hongkong dot 1 at gmail dot com
Summary: 7.1.0 changed behaviour of &$this when used in
callback
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: 7.1.0
Block user comment: N
Private report: N
New Comment:
This change is caused by https://wiki.php.net/rfc/this_var, which no longer
allows taking a reference to $this (instead, you will get a value).
We changed call_user_func_array() in 7.1 to still perform the call (even though a warning is
emitted) to make sure this and similar discrepancies do not cause BC breaks beyond additional
warnings.
The correct way of fixing this is to stop using by-reference argument passing for this parameter.
You don't need it since PHP 4.
Previous Comments:
------------------------------------------------------------------------
[2016-12-15 18:18:49] jamesin dot hongkong dot 1 at gmail dot com
Description:
------------
https://3v4l.org/vMc1N contains the sample code where
&$this as part of the callback invocation:
```
Hooks::run( 'foo', array( &$this, &$var ) );
```
causes a "Warning: Parameter 1 to {closure}() expected to be a reference, value given" on
7.1.0.
Running the provided sample code on 5.3.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.10 works as
expected.
Re-declaring $this will pass on 7.1.0 and 5.3.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.10.
```
$foo = $this;
Hooks::run( 'foo', array( &$foo, &$var ) );
```
Test script:
---------------
https://3v4l.org/vMc1N
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73751&edit=1
Thread (2 messages)