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
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:
MUST BE VALID
Solve the problem:
50 - 46 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC