|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
37 - 12 = ?
Subscribe to this entry?

 [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: Sun Apr 14 05:01:28 2024 UTC