Re: [PHP] Class Auto-Assigning to Variable

[email protected] ("Brian Smither")
Newsgroups php.general
Message-ID <[email protected]>
>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

Or relevant code having a side-effect not currently realized.


>Is your class maybe inheriting from another one and that contains the code
>causing this issue?

No.


>>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.


Let's refine the conceptual example:
 
class Hello {
private $_world = 'World';
function __construct(){}
}

$GLOBALS['hello'] = new Hello();

echo 'The variable $hello is '.gettype($hello)."\n".print_r($hello,true);

Can we then postulate that the value of $GLOBALS['hello'] will also be revealed in $hello, even though $hello was never formally declared?

I know that $GLOBALS['hello'] has a universal scope, and $hello (wherever it comes from) needs to be global-ized inside functions.
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.