Doc #76411 [Opn]: Should state that function arguments are passed by reference if objects
Edit report at https://bugs.php.net/bug.php?id=76411&edit=1
ID: 76411
Updated by: cmb@php.net
Reported by: teo8976 at gmail dot com
Summary: Should state that function arguments are passed by
reference if objects
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
> 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;
}
vs.
function foo(&$object) {
$object = null;
}
Only the latter has an effect which can be observed outside the
function; see <https://3v4l.org/04vX5>.
Previous Comments:
------------------------------------------------------------------------
[2018-06-03 18:56:27] teo8976 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/functions.arguments
---
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:
http://docs.php.net/manual/en/language.operators.assignment.php
"""
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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76411&edit=1
Thread (6 messages)