From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      4.0.4pl1
PHP Bug Type:     Class/Object related
Bug description:  Calling an object's method changes the variable to a reference to 
this object.

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 Bug report at: http://bugs.php.net/?id=11543&edit=1



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to