|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35865 Undocumented change to behaviour of references
Submitted: 2006-01-01 02:36 UTC Modified: 2006-09-15 01:00 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: tigerincanada at gmail dot com Assigned:
Status: No Feedback Package: Documentation problem
PHP Version: 4.4.1 OS: Linux 2.4.20 (Red Hat)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-01-01 02:36 UTC] tigerincanada at gmail dot com
After upgrading to PHP 4.4.1 I started seeing "Fatal error: Call to a member function on a non-object" where previously there had been none.  

It appears that the behaviour of references has changed, so the the reuse of a variable name no longer unassigns that variable name from earlier copies of the previous contents of that variable.  

The attempt at a reproduce code below doesn't actually cause the bug to reproduce, but illustrates the type of code that was causing the problem.  I haven't worked out what feature of my more complex production code is causing the issue, but it wasn't there before upgrading to from 4.3.11 to 4.4.1.

Googling "Fatal error: Call to a member function on a non-object PHP 4.4.1" shows up a few other people who appear to have run into a similar unexpected issue.

Reproduce code:
Class Foo
  var $name;

  function Foo($n) {
    $this->name = $n;

  function getName() {
    return $this->name;

$result =& new Foo("First");

$c =& $result;

$b = "Second";

$result =& $b;

print $c->getName();

Expected result:

Actual result:
Attempted reproduce code: "First"

Production code: "Fatal error: Call to a member function on a non-object"

In production, querying the zval of $c finds that it has somehow been set to the value of on the the object's properties... major head-scratcher!  

When I changed the code to remove the variable re-use, like this:

$c =& new Foo("First");

$b = "Second";

$result =& $b;

The problem went away...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-07 10:05 UTC]
I don't get it. What exactly are you expecting to document?
 [2006-09-15 01:00 UTC] phpdoc at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 14 11:01:23 2021 UTC