|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60059 Passing by Reference also accepts array elements
Submitted: 2011-10-13 23:09 UTC Modified: 2011-12-03 23:28 UTC
From: chealer at gmail dot com Assigned:
Status: Not a bug 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: chealer at gmail dot com
New email:
PHP Version: OS:


 [2011-10-13 23:09 UTC] chealer at gmail dot com
According to :

The following things can be passed by reference:

    Variables, i.e. foo($a)
    New statements, i.e. foo(new foobar())

    References returned from functions, i.e.:

No other expressions should be passed by reference, as the result is undefined.

This appears to be inexact. Elements of array variables can apparently also be passed by reference, unless this works by chance.

Test script:
function two(&$int) {
	$int = 2;

$a = array(1);

Actual result:
array(1) { [0]=> int(2) } 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-03 23:28 UTC]
-Status: Open +Status: Bogus
 [2011-12-03 23:28 UTC]
When passing an "array element", you are just passing a reference to the value 
stored there. This is equivalent to saying that "variables" can be passed by 
reference. One can also pass properties by reference, or whatever else qualifies 
as a variable.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Mar 03 22:01:25 2021 UTC