From:             php at pollensoft dot com
Operating system: Gentoo Linux
PHP version:      4.3.11
PHP Bug Type:     Scripting Engine problem
Bug description:  Return by reference is redundant

Description:
------------
This is a feature request.

Return by reference is redundant, see code examples below.

In order to return by reference, you must assign by reference.  Return by
reference syntax has no effect on what is returned.

Understanding that this is the expected behaviour ($me->RTFM() == true),
one or the other should be sufficient to retrieve by reference.

if `get` is executed with or without the return by reference definition
`function &get()` the result is the same (it's always a reference).

`function &functionName()` does nothing unless the assignment is by
reference -- ever.

When doing this in an OOP method, `&functionName()` should be all that is
necessary to return the reference to ensure that a developer using a class
doesn't need to remember to assign the value as a reference.

We mind as well use the language structures you've provided us with :)  I
would suggest either making it work or removing return by reference from
all of the documentation..

See also 
http://bugs.php.net/bug.php?id=9453.
http://bugs.php.net/bug.php?id=29877


Reproduce code:
---------------
class A {
        function A() {
                $this->arr = array();
        }

        function &getref() {
                return $this->arr;
        }

        function getval() {
                return $this->arr;
        }
}

$b = new A;
$c =& $b->getref(); // $c = reference (expected)
$c =& $b->getval(); // $c = reference (expected)
$c = $b->getval(); // $c = value (expected)
$c = $b->getref(); // $c = value (redundant)


-- 
Edit bug report at http://bugs.php.net/?id=33510&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33510&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33510&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33510&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33510&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33510&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33510&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33510&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33510&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33510&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33510&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33510&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33510&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33510&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33510&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33510&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33510&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33510&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33510&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33510&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33510&r=mysqlcfg

Reply via email to