ID: 24687
Updated by: andi@php.net
Reported By: nologic at pchome dot com dot tw
-Status: Assigned
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS
Assigned To: zeev
New Comment:
This bug has been fixed in CVS.
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/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2003-11-28 23:38:39] sniper@php.net
Zeev, please, either fix this or set the status to 'wont fix'.
------------------------------------------------------------------------
[2003-11-27 14:53:01] zhundiak at comcast dot net
This bug pretty much rules out backwards compatibility with most php4
OOP programs. It's quite silly to say that returning a reference by
calling another function that returns a reference is "bad" programing
practice. And by the way, C++ has no problem with returning pointers.
Just to be clear:
function &getHomeTeam()
{
return $this->getTeam(TEAM_TYPE_HOME);
}
Really should work.
------------------------------------------------------------------------
[2003-11-19 21:26:10] kain at kuht dot it
and this?
Fatal error: Only variables or references can be returned by reference
in /usr/lib/php/DB/common.php on line 766
function &query($query, $params = array()) {
if (sizeof($params) > 0) {
$sth = $this->prepare($query);
if (DB::isError($sth)) {
return $sth;
}
$ret = $this->execute($sth, $params);
$this->freePrepared($sth);
return $ret;
} else {
$result = $this->simpleQuery($query);
if (DB::isError($result) || $result === DB_OK) {
return $result;
} else {
-->766 return new DB_result($this, $result);
}
}
}
running on Apache/2.0.48 (Trustix Secure Linux/Linux) PHP/5.0.0b2
------------------------------------------------------------------------
[2003-11-17 02:35:55] mag at alcormizar dot cjb dot net
I agree with Zeev on this one, this shouldn't be fixed. People will
need to learn to write good code one day or the other, and returning a
reference like that is VERY bad practice (try to do that in C++!). Even
returning a reference to a local variable like this example should
produce an error :
class foo
{
function &bar()
{
$whatever = 5;
return $whatever;
}
}
because $whatever should not exist anymore after function bar return
(according to correct scope rules), thus this reference is not
referencing anything anymore... Instead of always asking to fix bad
programming practice people should learn the correct way to do it. This
is my opinion.
------------------------------------------------------------------------
[2003-08-16 04:14:19] jan at horde dot org
Any idea yet if this will be fixed/addressed or should we start
converting scripts to not use referenced return type or build variables
that get returned?
------------------------------------------------------------------------
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/24687--
Edit this bug report at http://bugs.php.net/?id=24687&edit=1