php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33352 returning references document says that class methods return reference is wrong
Submitted: 2005-06-15 15:58 UTC Modified: 2005-07-14 11:50 UTC
From: cmoore at iyd dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Gentoo Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cmoore at iyd dot com
New email:
PHP Version: OS:

 

 [2005-06-15 15:58 UTC] cmoore at iyd dot com
Description:
------------
On the document page:
http://us2.php.net/manual/en/language.references.return.php

"& by function definition is optional in class methods."



Reproduce code:
---------------
<?
class reftest
{
  var $var = "original";

  function by_copy()
  {
    return $this->var;
  }
}

print "By copy:\n";
$t = new reftest;
var_dump($t);
$c =& $t->by_copy();
$c = "copy";
var_dump($t);


Expected result:
----------------
According to docs, $c should be a reference to the class variable. $t->c should have the value "copy" in the output from the last var_dump. When an ampersand is prefixed on the function by_copy(), it works as expected.


Actual result:
--------------
as demonstrated by the above code, a copy is returned.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-15 16:11 UTC] vrana@php.net
Fur further reference: it was added for the sake of bug #29877.
 [2005-07-14 11:50 UTC] vrana@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

Already fixed by Derick.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 12:01:33 2025 UTC