php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49147 "What references do" docs are incorrect
Submitted: 2009-08-04 03:02 UTC Modified: 2009-11-16 12:06 UTC
From: initcontact at grahamwideman dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2009-08-04 03:02 UTC] 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










Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-16 12:06 UTC] vrana@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 4 only note removed.
 [2009-11-16 12:06 UTC] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=290810
Log: Remove PHP 4 only note (bug #49147)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 16:01:34 2024 UTC