note 14661 rejected and deleted from language.references.php by alindeman
| From: | alindeman@php.net | Date: | Mon, 13 Aug 2001 21:17:21 +0000 |
| Subject: | note 14661 rejected and deleted from language.references.php by alindeman | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-16663@lists.php.net to get a copy of this message | ||
When using references in a class I observed the following strange behaviour, which I could not
understand. Say we have a class such as:
$ref = "NULL";
class foo
{
// some fn, not necessarily constructor
function someFn()
{
global $ref;
$ref = & $this;
}
}
// We then create an instance of this class
$test = new foo();
$test->someFn();
echo $ref; // REF IS NULL
Strangely enough this problem is solved by doing the following:
$ref = array();
// inside someFn()
$ref[] = & this;
Now ref[0] does contain a valid reference to my class. This does not make any sense to me.