php.net |  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
Votes:1
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
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
20 + 13 = ?
Subscribe to this entry?

 
 [2006-01-01 02:36 UTC] tigerincanada at gmail dot com
Description:
------------
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:
----------------
"First"

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...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-07 10:05 UTC] bjori@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC