Re: Class Auto-Assigning to Variable
| From: | Ashley Sheridan | Date: | Wed, 07 Aug 2013 23:10:35 +0000 |
| Subject: | Re: Class Auto-Assigning to Variable | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-321813@lists.php.net to get a copy of this message | ||
>I have two dozen classes in this application. In every case, there will
>be a variable, the name of which is a lowercase variant of the class
>name, to which is assigned an instance of the class, when the class's
>construct() function completes. The example informs you of this.
>
Actually, as we've explained, your example does _not_ show this, it works as expected and
throws a notice, from which can be inferred there is other code doing this
>> I would say for definite that it's some of the surrounding code,
>
>Exactly. No sooner and no later than precisely when the class's
>construct() function ends, and control is given to the next statement
>after the one that instantiated that class.
>
Is your class maybe inheriting from another one and that contains the code causing this issue?
>
>> probably something similar to this:
>
>Let's explore this statement:
>
>> $GLOBALS[strtolower(get_class($this))] = $this;
>
>May I infer that the declaration of $GLOBALS['hello'] will, at the same
>time, also create $hello (without a statement declaring such)?
The $GLOBALS array is what's known as a super global. Elements within the array are reflected
as global variables and vice-versa.
>
>This:
>http://php.net/manual/en/reserved.variables.globals.php
>implies the opposite direction.
>
Not sure what you mean, but this super global works both ways. Don't necessarily get hung up on
this being the exact code, it's just a proof of concept of how it /might/ be happening. Like I
said, there are probably other ways too.
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
Thanks,
Ash