ID:               41117
 Comment by:       judas dot iscariote at gmail dot com
 Reported By:      hannes dot magnusson at gmail dot com
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: FreeBSD
 PHP Version:      5CVS-2007-04-17 (CVS)
 New Comment:

AFAICS, $this should not be altered(reasigned) in anyway.
this should "Fatal error : cannot reassign $this" I guess.


Previous Comments:
------------------------------------------------------------------------

[2007-04-17 12:28:26] hannes dot magnusson at gmail dot com

Description:
------------
Using $this as parameter is possible, but when using it (except from
printing it out) $this referes to itself

It is also possible to change $this via reference.
The object name seems to get changed - but when using it it works fine.

Reproduce code:
---------------
<?php
class foo {
        function __construct($this) {
                printf("ctor \$this parameter is: %s\n",
var_export($this, 1));
                self::overwrite($this);

                printf("Returning from self::overwrite \$this is: %s",
get_class($this));
                $this->hello();
        }
        function overwrite(&$obj) {
                $obj = new stdclass;
                printf("self::overwrite \$this is: %s\n",
get_class($this));
        }
        function hello() {
                printf(" ...lier! \$this is still %s\n",
get_class($this));
        }
}
$obj = new foo("Hello world");
var_dump($obj);



Actual result:
--------------
ctor $this parameter is: 'Hello world'
self::overwrite $this is: foo
Returning from self::overwrite $this is: stdClass ...lier! $this is
still foo
object(foo)#1 (0) {
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=41117&edit=1

Reply via email to