|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-05-23 21:01 UTC] pollita@php.net
[2005-06-20 09:57 UTC] skissane at iips dot mq dot edu dot au
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 06:00:01 2025 UTC |
Description: ------------ Trying to assign to $this inside a method results in: "Fatal error: Cannot re-assign $this". However, using a reference it is possible to modify $this. Reproduce code: --------------- class A { function f() { $p =& $this; $p = "whatever"; var_dump($this); // Note: accessing fields and invoking methods // via $this still works fine. } }; $x = new A(); $x->f(); Expected result: ---------------- Fatal error: Cannot re-assign $this Actual result: -------------- string(8) "whatever"