|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73751 7.1.0 changed behaviour of &$this when used in callback
Submitted: 2016-12-15 18:18 UTC Modified: 2016-12-16 21:13 UTC
From: jamesin dot hongkong dot 1 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jamesin dot hongkong dot 1 at gmail dot com
New email:
PHP Version: OS:


 [2016-12-15 18:18 UTC] jamesin dot hongkong dot 1 at gmail dot com
------------ 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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-16 21:13 UTC]
-Status: Open +Status: Not a bug
 [2016-12-16 21:13 UTC]
This change is caused by, 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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 09:01:41 2024 UTC