|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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 Apr 14 06:01:24 2021 UTC