pointers in php

From: Date: Wed, 22 Aug 2001 19:53:31 +0000
Subject: pointers in php
Groups: php.general 
Request: Send a blank email to php-general+get-63960@lists.php.net to get a copy of this message
Hi, I have a problem with pointers in php. In the following code the parent object should be a pointer to class Main ($this), but it's a copy ... Any ideas ? Thx Chris <?php class Sub_A { // constructor function Sub_A(&$parent) { $this->parent = &$parent; } function Modify($text) { $this->parent->B->text = $text; } } class Sub_B { var $text = "untouched"; // constructor function Sub_B(&$parent) { $this->parent = &$parent; } } class Main { // constructor function Main() { $this->A = new Sub_A($this); $this->B = new Sub_B($this); } } $test = new Main(); $test->A->Modify('test'); // this method should work, but doesnt (should return "test" instead of "untouched") echo $test->B->text."<br>"; // parent isnt a pointer but a copy so absolute addressing works echo $test->A->parent->B->text."<br>"; ?>

« previous php.general (#63960) next »