From:             tigerincanada at gmail dot com
Operating system: Linux 2.4.20 (Red Hat)
PHP version:      4.4.1
PHP Bug Type:     Class/Object related
Bug description:  Undocumented change to behaviour of references

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

-- 
Edit bug report at http://bugs.php.net/?id=35865&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35865&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35865&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35865&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=35865&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=35865&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=35865&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=35865&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=35865&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=35865&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=35865&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=35865&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=35865&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=35865&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=35865&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=35865&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=35865&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=35865&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=35865&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=35865&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=35865&r=mysqlcfg

Reply via email to