ID: 41117 Updated by: [EMAIL PROTECTED] Reported By: hannes dot magnusson at gmail dot com -Status: Assigned +Status: Wont fix Bug Type: Scripting Engine problem Operating System: FreeBSD PHP Version: 5CVS-2007-04-17 (CVS) Assigned To: dmitry New Comment:
The part of the bug that allows use $this as argument name is fixed in CVS HEAD ans PHP_5_2. However reassignment $this by reference is still possible and won't be fixed (at least in php 5.2). You can use easest code to do this $obj =& $this; $obj = new stdClass(); Both statements are legal, but their combination makes illegal assignment that cannot be detected. Previous Comments: ------------------------------------------------------------------------ [2007-04-17 16:35:50] judas dot iscariote at gmail dot com AFAICS, $this should not be altered(reasigned) in anyway. this should "Fatal error : cannot reassign $this" I guess. ------------------------------------------------------------------------ [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