|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-01-30 12:28 UTC] colleen at surfmerchants dot com
[2002-02-26 21:36 UTC] yohgaki@php.net
[2002-06-08 00:33 UTC] zionglau at yahoo dot com
[2002-06-08 06:32 UTC] mfischer@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 03:00:01 2025 UTC |
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>"); ?>