php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15599 functions returning references, oddity(?)
Submitted: 2002-02-18 10:33 UTC Modified: 2003-02-08 12:53 UTC
From: anders at gatefive dot fi Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.1.1 OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: anders at gatefive dot fi
New email:
PHP Version: OS:

 

 [2002-02-18 10:33 UTC] anders at gatefive dot fi
I think it is a bit funny that when returning references from functions you get something looking kind of this in the end:
$a = & & $b;

That is, I think it would be more logic if a function that is specified to return a reference wouldn't need to be set on the return side to return a reference.. since I doesn't make my self clear, here is as an example what I mean:

class a {
  var $b;
  function &fc() {
    return $this->b;
  }
}

$c = new a();
// A)
$myvar = $c->fc();
-----------------------------------
Now this will not work as I seem would be logical, instead one need to do the last line:
// B)
$myvar = &$c->fc();

This seems funny.. My logic says that since the function is defined to return a reference it would be enough (A).. no need to do it again like in (B). This is true when passing a reference: somefunc($myvar) will result in passing an reference if the func is defined like
function somefunc(&$arg)


Is there any chance of a change?
Opinions, comments etc. ?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-31 13:47 UTC] xuefer at 21cn dot com
don't think so

example:

$var = "a";   // var $c->b
$ref = &$var; // function $c->fc();

and how do u think about:
$a = $ref;    // $myvar = $c->fc();
and
$b = &$ref;   // $myvar = $c->fc();

which is copy and which is reference?
$a or $b?
 [2003-02-08 12:53 UTC] moriyoshi@php.net
We won't make such a change that would definitely break backwards compatibility even though the behaviour is not intuitive.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 14:01:30 2024 UTC