Re: Support of the $ref = &$obj ?
| From: | Christian Rishøj | Date: | Mon, 08 Jan 2001 13:24:33 +0000 |
| Subject: | Re: Support of the $ref = &$obj ? | ||
| References: | 1 | Groups: | php.pear |
| Request: | Send a blank email to php-pear+get-865@lists.php.net to get a copy of this message | ||
I correct myself:
The =& operator works fine. I was confused by the following:
<?php
$array = array();
class foo {
var $bar = 0;
function foo() {
global $array;
$array[] =& $this;
}
function setBar() {
$this->bar = 1;
}
}
$dimmer = new foo;
$dimmer->setBar();
echo 'Global: '.$dimmer->bar.'<br>';
$referenced = $array[0];
echo 'Reference: '.$referenced->bar.'<br>';
?>
It outputs:
Global: 1
Reference: 0
This leads me to the conclusion, that _after_ the contructer has run, a
_copy_ of the object is returned by the 'new' command. Therefore the
reference in $array is not a reference to the object returned by 'new foo'.
Does anybody have a workaround for this?
I'd rather avoid have to call a second 'register yourself' method after
having instaciated the object - which would do as I want.
/Christian
----- Original Message -----
From: "Christian Rishøj" <chrris@mail.dk>
To: <php-pear@lists.php.net>
Sent: Monday, January 08, 2001 1:38 PM
Subject: [PHP-PEAR] Support of the $ref = &$obj ?
> Hi,
>
> I have noticed the use of
>
> $_PEAR_destructor_object_list[] = &$this;
>
> ...to assign a reference to rval to lval.
>
> However, having tried this with PHP 4.0.2 myself, I am quite convinced
that
> I get a seperate copy of the object instead of the desired reference.
>
> I recall some notes about the &$obj way of returning references wasn't
> supported yet. Can anybody give me a status on this?
>
> /Christian
>
>
> --
> PHP Extension and Add-on Repository (PEAR) mailing list.
> Documentation can be found at http://pear.php.net/doc/pear.html
> To unsubscribe, e-mail: php-pear-unsubscribe@lists.php.net from the
> mail address you subscribed with.
>
>