php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42810 Returning References example is unclear
Submitted: 2007-10-01 06:14 UTC Modified: 2007-11-12 22:55 UTC
From: aharvey@php.net Assigned: felipe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2007-10-01 06:14 UTC] aharvey@php.net
Description:
------------
The example for the "Returning References" page <http://us3.php.net/manual/en/language.references.return.php> handwaves the fact that $found_var needs to be set to either a reference or concrete value within the /* ...code... */ block, which is a potential source of confusion for newer programmers, judging by the conversation I just had on ##php. The following may be a clearer and more complete example for users to demonstrate the concept:

<?php
class C {
        public $value = 42;

        public function &getValue() {
                return $this->value;
        }
}

$c = new C;
$myValue = &$c->getValue();   // $myValue is a reference to $c->value, which is 42.
$c->value = 2;
echo $myValue;                // prints the new value of $c->value, ie 2.
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-01 06:17 UTC] aharvey@php.net
Sorry, forgot about the line wrapping. I've put the example up at <http://www.adamharvey.name/stuff/php-bug-42810.phps>.
 [2007-11-12 22:55 UTC] felipe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 15:00:02 2026 UTC