|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
44 + 44 = ?
Subscribe to this entry?

 [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: Sun Apr 11 08:01:23 2021 UTC