|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-04-17 16:35 UTC] judas dot iscariote at gmail dot com
[2007-05-02 13:27 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 16:00:02 2025 UTC |
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) { }