ID: 7455
Updated by: sniper
Old-Status: Duplicate
Status: Closed
Bug Type: *General Issues
Assigned To: 

Previous Comments:

[2000-10-25 13:09:24] [EMAIL PROTECTED]
I have been working on a very reference intensive project and have run into a number 
of problems.  This is one that I've been able to pin down to a fairly simple example.

The basic idea of the bug is that it appears $this is a different value in the 
constructor of a class then it is outside of the constructor.

Take this example:
global $GlobaBlow;      //will hold the reference of $blow

class foobar {
        var $State;     //Holds the current state of an instanticated class
        function foobar() {
                $this->work();  //Sets GlobalBlow to the reference of the instanciated 
                $this->State = "In Constructor";        //Sets the state of the 
instanciated class to "In Constructor"
        function work() {
                $GLOBALS["GlobalBlow"] =& $this;        //Assigns the Global variable 
the reference to this instanciated class

$blow = new foobar();   //creates a new foobar
$blow->State = "Global";        //sets the state of the instanciated foobar to 
echo $GlobalBlow->State;        //should display "Global" but instead displays "In 

Whatever $this was pointing to when it was assigned to the global variable is 
different then the $this assigned to the global variable outside of the constructor.  
You can see this just by moving the call to $blow->work from within the constructor to 
outside of the constructor.

If this is done then the correct value of "Global" is displayed.

Please don't hassle me on uselessness of the example. :)  I know it's useless but 
where we're using it in our project it is a must.  Our project relies heavily on the 
ability to assign $this to a variable from within constructors.

Thanks tons for your help,


ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to