Doc #60059 [Opn->Bgs]: Passing by Reference also accepts array elements

From: Date: Sat, 03 Dec 2011 23:28:14 +0000
Subject: Doc #60059 [Opn->Bgs]: Passing by Reference also accepts array elements
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7532@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60059&edit=1 ID: 60059 Updated by: frozenfire@php.net Reported by: chealer at gmail dot com Summary: Passing by Reference also accepts array elements -Status: Open +Status: Bogus Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-10-13 23:09:13] 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) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60059&edit=1

« previous php.doc.bugs (#7532) next »