Re: [PHP] Class Auto-Assigning to Variable

[email protected] (Ashley Sheridan)
Newsgroups php.general
Message-ID <[email protected]>


>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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.