ID: 11543
Updated by: [EMAIL PROTECTED]
-Summary: Calling an object's method changes the variable to a
reference to this object.
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Linux
PHP Version: 4.0.4pl1
New Comment:
The version of PHP that this bug was reported in is too old. Please
try to reproduce this bug in the latest version of PHP (available
from http://www.php.net/downloads.php
If you are still able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Previous Comments:
------------------------------------------------------------------------
[2002-01-30 12:28:48] [EMAIL PROTECTED]
I'm definitely experiencing this bug, and it causes me to lose data
because the objects I'm using are contained in a session variable.
Because sessions don't transmit references, I lose any object whose
function I have called.
Right now I'm using a work-around where I assign the object to another,
temporary object, run the temp's function, and then copy the temp back
to the real object. That seems to work.
Is this problem fixed in newer versions of PHP? I'd rather not have to
use the work-around if it's not necessary.
Thanks.
------------------------------------------------------------------------
[2001-06-18 16:02:48] [EMAIL PROTECTED]
Hello!
The following code defines two classes. The first class (COuter)
contains a variable to which an instance of the second class (CInner)
is assigned.
After initializing this hierarchy, the script dumps out the hierarchy's
internal structure and tests if it its possible to copy the hierarchy.
Now the script calls method of the second object. This method just
outputs a short text and returns. After returning the script creates a
new dump and tests the possibility to copy the hierarchy again.
The two var-dumps should look like these:
Dump 1:
object(couter)(2) { ["T"]=> string(0) "" ["Inner"]=> object(cinner)(1)
{ ["T"]=> string(0) "" } }
Here the method is called!
Dump 2:
object(couter)(2) { ["T"]=> string(0) "" ["Inner"]=> &object(cinner)(1)
{ ["T"]=> string(0) "" } }
If you look closely at the two dumps, you will see, that variable Inner
becomes a reference in the second dump!
A look on the copy-tests verify the suppositon: The second copy-test
does not copy the object-hierarchy completely!
All I have to do to change the variable to a reference is: call a
function of the inner class!
I hope my description and the following code will help you to find the
bug, if it is one as I suppose.
Greetings,
Christoph Boehme.
<?
// Defining the classes:
class COuter
{var $T, $Inner;}
class CInner{
var $T;
function Func()
{echo("Calling CInner::Func();<br>");}
}
// Creating the object hierarchy:
$MyOuter =new COuter;
$MyOuter->T ="";
$MyOuter->Inner =new CInner;
$MyOuter->Inner->T ="";
// Dumping out the hierarchy's internal structure:
echo("Object structure of \$MyOuter:<br>");
var_dump($MyOuter);
echo("<br>");
// Testing if it is possible to copy the hierarchy:
$Copy1 =$MyOuter;
$Copy1->T ="Test";
$Copy1->Inner->T ="Test";
echo("\$Copy1->T: ". $Copy1->T ."<br>");
echo("\$MyOuter->T: ". $MyOuter->T ."<br>");
echo("\$Copy1->Inner->T: ". $Copy1->Inner->T ."<br>");
echo("\$MyOuter->Inner->T: ". $MyOuter->Inner->T ."<br><br>");
// Calling a method of the inner object:
$MyOuter->Inner->Func();
// Dumping out the hierarchy's structure again:
echo("<br>Object structure of \$MyOuter:<br>");
var_dump($MyOuter);
echo("<br>");
// Testing again if it is possible to copy the hierarchy:
$Copy2 =$MyOuter;
$Copy2->T ="Test";
$Copy2->Inner->T ="Test";
echo("\$Copy2->T: ". $Copy2->T ."<br>");
echo("\$MyOuter->T: ". $MyOuter->T ."<br>");
echo("\$Copy2->Inner->T: ". $Copy2->Inner->T ."<br>");
echo("\$MyOuter->Inner->T: ". $MyOuter->Inner->T ."<br>");
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=11543&edit=1