#42810 [Opn]: Returning References example is unclear
| From: | aharvey@php.net | Date: | Mon, 01 Oct 2007 06:17:04 +0000 |
| Subject: | #42810 [Opn]: Returning References example is unclear | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-50@lists.php.net to get a copy of this message | ||
ID: 42810
User updated by: aharvey@php.net
Reported By: aharvey@php.net
Status: Open
Bug Type: Documentation problem
Operating System: Irrelevant
PHP Version: Irrelevant
New Comment:
Sorry, forgot about the line wrapping. I've put the example up at
<http://www.adamharvey.name/stuff/php-bug-42810.phps>.
Previous Comments:
------------------------------------------------------------------------
[2007-10-01 06:14:41] 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.
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42810&edit=1