php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chealer at gmail dot com
New email:
PHP Version: OS:

 

 [2011-10-13 23:09 UTC] chealer at gmail dot com
Description:
------------
According to http://ca.php.net/manual/en/language.references.pass.php :

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:
---------------
<?php
function two(&$int) {
	$int = 2;
}

$a = array(1);
two($a[0]);
var_dump($a);


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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-03 23:28 UTC] frozenfire@php.net
-Status: Open +Status: Bogus
 [2011-12-03 23:28 UTC] frozenfire@php.net
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-2020 The PHP Group
All rights reserved.
Last updated: Wed Jun 03 14:01:25 2020 UTC