#34358 [Opn->Bgs]: Fatal error: Cannot re-assign $this(again)
| From: | sniper@php.net | Date: | Thu, 15 Sep 2005 12:26:02 +0000 |
| Subject: | #34358 [Opn->Bgs]: Fatal error: Cannot re-assign $this(again) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-85084@lists.php.net to get a copy of this message | ||
ID: 34358
Updated by: sniper@php.net
Reported By: pacha dot shevaev at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5.*
New Comment:
Heh, 2 PHP developers tell you it's not a bug and you still insist?
Come on..
Previous Comments:
------------------------------------------------------------------------
[2005-09-15 13:37:28] pacha dot shevaev at gmail dot com
I still find it a bug. I need a reference to $this for BC with PHP4 in
the following piece of code:
function &getRootDataSource() {
$root =& $this;
while ($root->parent != NULL) {
$root =& $root->parent;
}
return $root;
}
------------------------------------------------------------------------
[2005-09-03 13:44:07] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
[2005-09-03 13:41:15] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Objects are already references in PHP 5, thuse there is no sense in
...&$this in any way.
------------------------------------------------------------------------
[2005-09-03 13:36:57] pacha dot shevaev at gmail dot com
Description:
------------
PHP 5.1RC1 throws fatal error when some variable gets assigned with
$this by reference. However there's a workaround for this fatal error
which is very simple: using a helper function which simply returns the
passed argument by reference. I'm a bit lost here - what is the
expected behavior?
Yes, it may seem a bit weird to assign objects by reference in PHP5 but
if you keep your code base PHP4 compatible you know what i mean.
Reproduce code:
---------------
<?php
function & getRef(&$ref) {
return $ref;
}
class Foo {
function Foo() {
//$ref =& getRef($this); //works just fine
$ref =& $this; //throws "cannot re-assign $this" fatal
$ref->test();
}
function test() {
echo 'test';
}
}
$foo = new Foo();
?>
Expected result:
----------------
test
Actual result:
--------------
Fatal error: Cannot re-assign $this
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34358&edit=1