php-general Digest 7 Aug 2013 21:15:54 -0000 Issue 8325
Topics (messages 321805 through 321811):
Class Auto-Assigning to Variable
321805 by: Brian Smither
321806 by: Sebastian Krebs
321807 by: Brian Smither
321808 by: Ashley Sheridan
321809 by: Brian Smither
321810 by: Stuart Dallas
321811 by: Ashley Sheridan
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 ---
I have a situation where, for some unknown reason, where each class that
finishes its __contruct{} function, that class gets automatically assigned to a
variable - other than the variable I specify.
Conceptually:
class Hello { private $_world = 'World'; __construct(){} }
$clsHello = new Hello();
echo 'The variable $hello is '.gettype($hello)."\n".print_r($hello,true);
Output:
The variable $hello is object
Hello Object
(
[_world:Hello:private] => World
)
There is no statement in my application that assigns an instance of the class
to another variable, the name being a lowercase variant of the class name.
Would there be a PHP function that would do this as a side-effect?
I am more interested in learning what is happening as opposed to rolling back
to a previous version. (A backup copy functions fine. A file compare does not
reveal any likely suspects.)
PHP5.4.17-NTS-VC9 (Windows XP-SP3)
--- End Message ---
--- Begin Message ---
2013/8/7 Brian Smither <bhsmit...@gmail.com>
> I have a situation where, for some unknown reason, where each class that
> finishes its __contruct{} function, that class gets automatically assigned
> to a variable - other than the variable I specify.
>
> Conceptually:
>
> class Hello { private $_world = 'World'; __construct(){} }
>
This isn't even valid PHP
$ php -a
Interactive shell
php > class Hello { private $_world = 'World'; __construct(){} }
PHP Parse error: syntax error, unexpected '__construct' (T_STRING),
expecting function (T_FUNCTION) in php shell code on line 1
php >
> $clsHello = new Hello();
>
> echo 'The variable $hello is '.gettype($hello)."\n".print_r($hello,true);
>
> Output:
> The variable $hello is object
> Hello Object
> (
> [_world:Hello:private] => World
> )
>
> There is no statement in my application that assigns an instance of the
> class to another variable, the name being a lowercase variant of the class
> name.
>
> Would there be a PHP function that would do this as a side-effect?
>
> I am more interested in learning what is happening as opposed to rolling
> back to a previous version. (A backup copy functions fine. A file compare
> does not reveal any likely suspects.)
>
> PHP5.4.17-NTS-VC9 (Windows XP-SP3)
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
github.com/KingCrunch
--- End Message ---
--- Begin Message ---
Second go around:
I have a situation where, for some unknown reason, where each class that
finishes its __contruct{} function, that class gets automatically assigned to a
variable - other than the variable I specify.
Conceptually (a little bit better on the conceptualizing):
class Hello {
private $_world = 'World';
function __construct(){}
}
$clsHello = new Hello();
echo 'The variable $hello is '.gettype($hello)."\n".print_r($hello,true);
Output:
The variable $hello is object
Hello Object
(
[_world:Hello:private] => World
)
There is no statement in my application that assigns an instance of the class
to another variable, the name being a lowercase variant of the class name.
Would there be a PHP function that would do this as a side-effect?
I am more interested in learning what is happening as opposed to rolling back
to a previous version. (A backup copy functions fine. A file compare does not
reveal any likely suspects.)
PHP5.4.17-NTS-VC9 (Windows XP-SP3)
--- End Message ---
--- Begin Message ---
On Wed, 2013-08-07 at 13:11 -0600, Brian Smither wrote:
> Second go around:
>
> I have a situation where, for some unknown reason, where each class that
> finishes its __contruct{} function, that class gets automatically assigned to
> a variable - other than the variable I specify.
>
> Conceptually (a little bit better on the conceptualizing):
>
> class Hello {
> private $_world = 'World';
> function __construct(){}
> }
>
> $clsHello = new Hello();
>
> echo 'The variable $hello is '.gettype($hello)."\n".print_r($hello,true);
>
> Output:
> The variable $hello is object
> Hello Object
> (
> [_world:Hello:private] => World
> )
>
> There is no statement in my application that assigns an instance of the class
> to another variable, the name being a lowercase variant of the class name.
>
> Would there be a PHP function that would do this as a side-effect?
>
> I am more interested in learning what is happening as opposed to rolling back
> to a previous version. (A backup copy functions fine. A file compare does not
> reveal any likely suspects.)
>
> PHP5.4.17-NTS-VC9 (Windows XP-SP3)
>
>
>
>
I cannot replicate this. That code you supplied correctly gives a notice
warning about an undefined variable '$hello'. Are you sure that that
simple code excerpt is giving you the problem you describe and there's
not more to the whole thing, more code, etc?
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
>I cannot replicate this.
I don't expect anyone to be able to replicate this behavior. The example shows
an extraordinarily stripped-down sequence of statements that informs what
should work, but do to some unknown agent, which, therefore, cannot be included
in the example, produces unexpected output.
This conceptual example is not a 'sample' or 'excerpt' of the actual
application. There is much, much more code. None of it is an apparent likely
suspect in causing this behavior.
I am hoping for a, "Oh, yeah! I've seen that happen before. It's caused by..."
Let us focus on the central question:
Would there be a PHP function that would do [what the example describes] as a
side-effect?
--- End Message ---
--- Begin Message ---
On 7 Aug 2013, at 20:45, "Brian Smither" <bhsmit...@gmail.com> wrote:
>> I cannot replicate this.
>
> I don't expect anyone to be able to replicate this behavior. The example
> shows an extraordinarily stripped-down sequence of statements that informs
> what should work, but do to some unknown agent, which, therefore, cannot be
> included in the example, produces unexpected output.
>
> This conceptual example is not a 'sample' or 'excerpt' of the actual
> application. There is much, much more code. None of it is an apparent likely
> suspect in causing this behavior.
>
> I am hoping for a, "Oh, yeah! I've seen that happen before. It's caused by..."
>
> Let us focus on the central question:
>
> Would there be a PHP function that would do [what the example describes] as a
> side-effect?
Yes:
$hello = $clsHello;
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) and none of them will assign a
userland object. 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.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--- End Message ---
--- Begin Message ---
On Wed, 2013-08-07 at 21:02 +0100, Stuart Dallas wrote:
> On 7 Aug 2013, at 20:45, "Brian Smither" <bhsmit...@gmail.com> wrote:
>
> >> I cannot replicate this.
> >
> > I don't expect anyone to be able to replicate this behavior. The example
> > shows an extraordinarily stripped-down sequence of statements that informs
> > what should work, but do to some unknown agent, which, therefore, cannot be
> > included in the example, produces unexpected output.
> >
> > This conceptual example is not a 'sample' or 'excerpt' of the actual
> > application. There is much, much more code. None of it is an apparent
> > likely suspect in causing this behavior.
> >
> > I am hoping for a, "Oh, yeah! I've seen that happen before. It's caused
> > by..."
> >
> > Let us focus on the central question:
> >
> > Would there be a PHP function that would do [what the example describes] as
> > a side-effect?
>
> Yes:
>
> $hello = $clsHello;
>
> 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) and none of them will
> assign a userland object. 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.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
As you've said that your excerpt doesn't replicate the problem, it's not
that useful really to accurately illustrate it. I would say for definite
that it's some of the surrounding code, probably something similar to
this:
class Hello
{
private $_world = 'World';
function __construct(){}
function test()
{
$GLOBALS[strtolower(get_class($this))] = $this;
}
}
$clsHello = new Hello();
$clsHello->test();
echo 'The variable $hello is
'.gettype($hello)."\n".print_r($hello,true);
There are probably many ways to achieve this, I can't think of a sane
reason for any of them though!
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---