#20739 [Ver->]: parentheses surrounding return()'s arguments do seem to matter
| From: | andi@php.net | Date: | Mon, 09 Dec 2002 12:41:22 +0000 |
| Subject: | #20739 [Ver->]: parentheses surrounding return()'s arguments do seem to matter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-27166@lists.php.net to get a copy of this message | ||
ID: 20739
Updated by: andi@php.net
Reported By: c.gerlach@sympatico.ca
-Status: Verified
+Status: Won\'t fix
Bug Type: Scripting Engine problem
Operating System: All
PHP Version: 4.3.0-dev/4.4.0-dev
New Comment:
You are right they do matter. When you're putting paratheses you're
telling the engine that this is an expression with a possible value
(e.g. (3+2) ) and not a variable.
Previous Comments:
------------------------------------------------------------------------
[2002-11-30 16:00:59] iliaa@php.net
In addition to returning the wrong value the code produces a number of
memory leaks that are listed below.
/home/rei/PHP_CVS/php4/Zend/zend_execute.c(468) : Freeing 0x084F7E24
(12 bytes), script=r.php
/home/rei/PHP_CVS/php4/Zend/zend_hash.c(262) : Freeing 0x084F7DCC (40
bytes), script=r.php
Last leak repeated 1 time
/home/rei/PHP_CVS/php4/Zend/zend_hash.c(178) : Freeing 0x084FCBF4 (32
bytes), script=r.php
Last leak repeated 1 time
/home/rei/PHP_CVS/php4/Zend/zend_execute.c(1692) : Freeing 0x084FCB94
(44 bytes), script=r.php
/home/rei/PHP_CVS/php4/Zend/zend_variables.c(135) : Actual location
(location was relayed)
Last leak repeated 1 time
/home/rei/PHP_CVS/php4/Zend/zend_execute.c(471) : Freeing 0x084F96FC
(4 bytes), script=r.php
/home/rei/PHP_CVS/php4/Zend/zend_variables.c(111) : Actual location
(location was relayed)
/home/rei/PHP_CVS/php4/Zend/zend_execute.c(479) : Freeing 0x084F96BC
(12 bytes), script=r.php
/home/rei/PHP_CVS/php4/Zend/zend_execute.c(1986) : Freeing 0x084F960C
(44 bytes), script=r.php
/home/rei/PHP_CVS/php4/Zend/zend_API.c(565) : Actual location (location
was relayed)
------------------------------------------------------------------------
[2002-11-30 15:37:53] c.gerlach@sympatico.ca
I'm using PHP 4.2.3 on Windows NT 5.0 build 2195 (win2k)
along with Apache and stumbled across a strange behaviour
regarding return() arguments in parentheses.
Consider the following code:
class Node {
var $children;
var $name;
function Node($name) {
$this->children = array();
$this->name = $name;
}
function &add($n) {
$this->children[0] = $n;
return($this->children[0]); # these () make a difference
}
}
$t = new Node("top");
$node = new Node("foo");
$n = &$t->add($node);
$n->name = "bar";
print $n->name; # output: "bar"
print $t->children[0]->name; # output: "foo"
The code is working as expected (i.e., both times
"bar" is printed) when you remove the
parentheses from the return call in the add method.
According to the manual, parentheses in a return
call shouldn't make a difference.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20739&edit=1