ID: 31525
Updated by: [EMAIL PROTECTED]
Reported By: yml at yml dot com
-Status: Assigned
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2005-03-03
Assigned To: andi
New Comment:
Fixed in CVS HEAD and PHP_5_0.
Previous Comments:
------------------------------------------------------------------------
[2005-04-29 03:46:43] [EMAIL PROTECTED]
Andi, I think you once responded to similar issue regarding return()
with/without parenthesis..
------------------------------------------------------------------------
[2005-03-06 05:55:37] yml at yml dot com
Problem found.
Removing all the ()'s from reference returning functions and the
problem has completely disappeared.
However, the case should be caught by the parser and a warning
generated. Using parens around returns returning references will cause
symbol table corruption occassionally ...
------------------------------------------------------------------------
[2005-03-06 02:43:51] michaels at crye-leike dot com
True, if getThis() is declared to return a reference then everything
works as expected. However, looking through the original reproduce
code I noticed something else. If you add parentheses around $this in
getThis() then the unexpected behavior returns. Complete code:
<?php
class Foo {
function &getThis() {
return ($this);
}
function destroyThis() {
$baz =& $this->getThis();
}
}
$bar = new Foo();
$bar->destroyThis();
var_dump($bar);
?>
Produces:
NULL
Expected:
object(Foo)#1 (0) {
}
------------------------------------------------------------------------
[2005-03-06 01:50:27] yml at yml dot com
Unfortunately the shortened script works as it should if you declare
getThis to return a reference as in
function &getThis()
If however, you refer to the "too-long" script I put together at:
http://www.formvista.com/uploaded_files/php5_drops_object.php.txt
There is something different about it that causes $this to get dropped
even when the method is declared return-by-reference.
I haven't been able to narrow it down but it's entirely possible I'm
overlooking something obvious.
It's got to be something related to legacy pass by reference notation
=&. The strange thing is it worked in 5.0.1 and broke in 5.0.2 or .3.
------------------------------------------------------------------------
[2005-03-06 01:26:05] michaels at crye-leike dot com
FWIW, here's a shorter script that reproduces the problem for me on PHP
5.0.3:
<?php
class Foo {
function getThis() {
return $this;
}
function destroyThis() {
$baz =& $this->getThis();
}
}
$bar = new Foo();
$bar->destroyThis();
var_dump($bar);
?>
This outputs:
NULL
If I change the assign-by-reference operator (=&) to the normal
assignment operator (=) inside destroyThis(), I get:
object(Foo)#1 (0) {
}
Hope this helps...
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/31525
--
Edit this bug report at http://bugs.php.net/?id=31525&edit=1