note 14661 added to language.references.php

From: Date: Wed, 08 Aug 2001 14:19:38 +0000
Subject: note 14661 added to language.references.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16475@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. http://www.php.net/manual/en/language.references.php

« previous php.notes (#16475) next »