#49147 [Opn->Csd]: "What references do" docs are incorrect
| From: | vrana@php.net | Date: | Mon, 16 Nov 2009 12:06:07 +0000 |
| Subject: | #49147 [Opn->Csd]: "What references do" docs are incorrect | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3180@lists.php.net to get a copy of this message | ||
ID: 49147
Updated by: vrana@php.net
Reported By: initcontact at grahamwideman dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
PHP Version: Irrelevant
New Comment:
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 4 only note removed.
Previous Comments:
------------------------------------------------------------------------
[2009-08-04 03:02:37] initcontact at grahamwideman dot com
Description:
------------
This text:
"Since PHP 5, new returns a reference automatically, so using =& in
this context is deprecated and produces an E_STRICT message.
Note: Not using the & operator causes a copy of the object to be
made."
... and following text is incorrect. It was probably intended to refer
to the way PHP 4 used to work (but even then is not really correct.)
Reproduce code:
---------------
---
From manual page: language.references.whatdo
---
http://www.php.net/manual/en/language.references.whatdo.php
Expected result:
----------------
Issues:
1. "Since PHP 5, new returns a reference automatically"
What I think is correct: Since PHP 5, *in general* functions that
return an object return it as an *object Id*. This works like what some
other languages call a "reference", but in PHP the word "reference"
refers to something more like an alias. (See:
http://www.php.net/manual/en/language.oop5.references.php).
2. "Not using the & operator causes a copy of the object to be made."
I guess that was true in PHP 4. In PHP 5, in the following code the
plain "=" copies the object id:
$a1 = new A();
$a2 = $a1;
$a1->somemember = 3;
print $a2->somemember ; // prints 3
... and consequently $a2-> accesses same object as $a1->.
3. The comments on $this are problematic. I think it's just saying the
obvious, that $this operates on the particular object on which the
member was invoked.
4. "Usually you want to have a single instance to work with, due to
performance and memory consumption issues." That seems like a red
herring -- a programmer chooses to have one instance or several
instances because they either want a single collection of data, or they
want multiple similar-structured collections of data. If the programmer
wanted a single instance, but accidentally created several, then that's
a logical problem before it's a performance problem (and vice versa).
Hope that's all clear,
-- Graham
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49147&edit=1