php-general Digest 8 Aug 2013 17:32:46 -0000 Issue 8326

Topics (messages 321812 through 321816):

Re: Class Auto-Assigning to Variable
        321812 by: Brian Smither
        321813 by: Ashley Sheridan
        321814 by: Brian Smither
        321815 by: Ashley Sheridan

Operand error...
        321816 by: Karl-Arne Gjersøyen

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
> $hello = $clsHello;

If that conceptual statement (or any occurance of the conceptual $hello) were 
in the code, then my (really good) Find feature of my code editor would have 
found it.


> There are only a few variables that get assigned as side effects of
>  functions, but they have very specific names, and none of them are
> $hello (but I'm guessing that's not the actual variable name)

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.


> Somewhere in your code there is something that is assigning to $hello.
> Find everything that's doing that and look at each instance in detail.

I have. Many times. What I am looking for is a side-effect -- something not 
obvious. (This application does not use an eval() function where some 
obfuscated string manipulation would play this out.)


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


> 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)?

This:
http://php.net/manual/en/reserved.variables.globals.php
implies the opposite direction.





--- End Message ---
--- Begin 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

--- End Message ---
--- Begin Message ---
>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.



--- End Message ---
--- Begin Message ---
On Wed, 2013-08-07 at 19:02 -0600, Brian Smither wrote:

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


No, you just didn't post relevant code.


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


$GLOBALS['hello'] is essentially a synonym for $hello in this context.
$GLOBALS is just an array of all variables that have global scope, so
adding to this causes variables to be added at the global scope level.
But, like I've said a few times, this might not be your specific
problem, and without seeing the actual code that causes this problem,
it's very difficult for anyone to help. Your code examples don't exhibit
the issue you describe, so they're not useful in the context of
pin-pointing the problem. If you can post code that *does* give that
problem, then someone on the list may be able to help.


Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
$oppdater_lager_med_antall_kg = $kg_pa_lager +
$kg_fra_transportdokument_inn_pa_valgt_lager;


result:
*Fatal error*: Unsupported operand types in *
/Users/karl/Sites/kasen/io/kp/index.php* on line *2970

*I have also tried this:
$kg_pa_lager += $kg_fra_transportdokument_inn_pa_valgt_lager;

Both of them return this Fatal error.
I am using Dreamweaver CS6 and the syntax check in my software say: "No
syntax error"

What am I doing wrong this time?

Thanks for your good advice!

Karl

--- End Message ---

Reply via email to