|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76411 Should state that function arguments are passed by reference if objects
Submitted: 2018-06-03 18:56 UTC Modified: 2018-06-03 21:49 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: teo8976 at gmail dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: teo8976 at gmail dot com
New email:
PHP Version: OS:


 [2018-06-03 18:56 UTC] teo8976 at gmail dot com
From manual page:

Where it says:
By default, function arguments are passed by value (so that if the value of the argument within the function is changed, it does not get changed outside of the function).

it should say that an exception to this are objects, which are passed by reference.

For comparison, the documentation for the assignment operator does specify that:
Note that the assignment copies the original variable to the new one (assignment by value), [...]
An exception to the usual assignment by value behaviour within PHP occurs with objects, which are assigned by reference

So, the documentation for function arguments should be equally clear and explicit.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-03 21:30 UTC]
> it should say that an exception to this are objects, which are
> passed by reference.

Note, though, that this would still be misleading.  Consider

  function foo($object) {
      $object = null;


  function foo(&$object) {
    $object = null;

Only the latter has an effect which can be observed outside the
function; see <>.
 [2018-06-03 21:49 UTC]
The "objects are passed by reference" statement is directly addressed in the OOP docs.
> One of the key-points of PHP 5 OOP that is often mentioned is that "objects are passed by references by default".
> This is not completely true. This section rectifies that general thought using some examples.

The terms "by value" and "by reference" refer to the concept of value-types and reference-types.
Those terms are being used correctly, but because PHP also has references the "by reference" is ambiguous.
 [2018-06-04 03:42 UTC] a at b dot c dot de
The line on the Assignment Operators page is the faulty one.

Assignment of objects is by value as well (an object's value is the object itself*; that value is the one that is assigned).

What assignment does not do is create a new object with the same properties as the object being assigned (that's what clone is for).

* Which is why objects are said to be passed by value to functions. Since the value of an object is the object itself, changing the passed object's properties changes the passed object's properties.
 [2023-04-21 10:26 UTC] buzzmeta35 at gmail dot com
Metabuzz360 are providitech, entertainment, health, home, real estate, business, finance etc. More info:(
 [2023-05-16 16:44 UTC] praveshppc at gmail dot com
We also accept guest posts related to the latest technology, finance, business, SEO, and much more.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 13 04:01:28 2024 UTC