Bug or Feature?
| From: | Teodor Cimpoesu | Date: | Thu, 29 Jun 2000 00:35:32 +0000 |
| Subject: | Bug or Feature? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3698@lists.php.net to get a copy of this message | ||
If I were absolutely sure I undestood 100% right the `&'
behaviour, that would be a bug report, but I though I should
ask first:
<?
class T {
function T ()
{
global $GLOB;
$this->t = &$GLOB;
}
function &get ($k)
{
return $this->t[$k];
}
}
$GLOB = array ('foo' => array ('bar' => 1));
$t = new T();
$f = $t->get('foo');
$g = &$t->get('foo');
++$f['bar'];
printf ("w/o &: %d\n", $GLOB['foo']['bar']);
++$g['bar'];
printf ("w/ &: %d\n" ,$GLOB['foo']['bar']);
prints:
1 2' and I would expect 2 2'
why ? because T::t gets a reference and T::get() returns a reference.
Also note that cute $g = &$t->method()' which is a desperation
inspiration' discovery, when everything went wrong in my code.
Is that documented, or I shouldn't use it this way?
-- teodor