|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-09-07 10:05 UTC] bjori@php.net
[2006-09-15 01:00 UTC] phpdoc at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
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...