[PHP-DOC] #20739 [Ana->Csd]: parentheses surrounding return()'s arguments do seem to matter

2003-08-15 Thread ali
 ID:   20739
 Updated by:   [EMAIL PROTECTED]
 Reported By:  c dot gerlach at sympatico dot ca
-Status:   Analyzed
+Status:   Closed
 Bug Type: Documentation problem
 Operating System: All
 PHP Version:  4.3.0-dev/4.4.0-dev
 New Comment:

This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:


[2002-12-09 07:14:40] [EMAIL PROTECTED]

The docs say different thing:

"Note:  Note that since return() is a language construct and not a
function, the parentheses surrounding its arguments are not
required--in fact, it is more common to leave them out than to use
them, although it doesn't matter one way or the other. "

This is not true, according to Andi..




[2002-12-09 06:41:21] [EMAIL PROTECTED]

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.



[2002-11-30 16:00:59] [EMAIL PROTECTED]

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 dot gerlach at sympatico dot 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


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DOC] #20739 [Ana->Csd]: parentheses surrounding return()'s arguments do seem to matter

2003-08-15 Thread ali
 ID:   20739
 Updated by:   [EMAIL PROTECTED]
 Reported By:  c dot gerlach at sympatico dot ca
-Status:   Analyzed
+Status:   Closed
 Bug Type: Documentation problem
 Operating System: All
 PHP Version:  4.3.0-dev/4.4.0-dev


Previous Comments:


[2002-12-09 07:14:40] [EMAIL PROTECTED]

The docs say different thing:

"Note:  Note that since return() is a language construct and not a
function, the parentheses surrounding its arguments are not
required--in fact, it is more common to leave them out than to use
them, although it doesn't matter one way or the other. "

This is not true, according to Andi..




[2002-12-09 06:41:21] [EMAIL PROTECTED]

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.



[2002-11-30 16:00:59] [EMAIL PROTECTED]

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 dot gerlach at sympatico dot 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


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php