What is $this ??

From: Date: Tue, 28 Mar 2000 19:18:33 +0000
Subject: What is $this ??
Groups: php.version4 
Request: Send a blank email to php-version4+get-12762@lists.php.net to get a copy of this message
Hi, Yea, I know that $this refers to the current object, but how? I have attempted to build a tree structure with child nodes containing a reference to thier parent but apache keeps segfaulting. (see the code below ) I'm using apache 1.3.11 with ssl on 2.2.11 linux (Redhat). Is there a 'better' way of achieving this (think doubley linked lists...) ? <?php class person{ function person($name="default_name", $kids=""){ $this->name=$name; if(is_array($kids))foreach($kids as $key => $val){ $val->parent=&$this; $this->kids[$val->name]=$val; } } function call_kids($func){ if(sizeof($this->kids)){ foreach($this->kids as $key => $val){ $val->call_kids($func); } } else{ $this->$func(); } } function lineage(){ $parent=&$this->parent; if(is_object($parent)){ // get the child to ask the parent echo $parent->lineage()." --> ".$this->name." "; } else{ echo "<BR>".$this->name; } } } $a=new person( "a", array( new person( "b", array( new person( "c" ) ) ), new person( "one", array( new person( "two" ) ) ) ) ); $a->call_kids("lineage"); ?> Here is the backtrace from gdb running httpd -X #0 0x4049b1ea in zend_fetch_var_address (result=0x8117b38, op1=0x8117b48, op2=0x8117b58, Ts=0xbf80002c, type=1) at ./zend_execute.c:462 #1 0x4049d687 in execute (op_array=0x8118b64) at ./zend_execute.c:1220 #2 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #3 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #4 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #5 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #6 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #7 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #8 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #9 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #10 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #11 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #12 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #13 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #14 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #15 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #16 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 #17 0x4049fad2 in execute (op_array=0x8118b64) at ./zend_execute.c:1624 <snip> this goes on for a couple of tens of thousands of repetitions.... -- Regards, Alan van den Bosch Sanguis Pty Ltd Mobile - 0408 106 872 /* All generalizations are false. */

« previous php.version4 (#12762) next »