php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62406 Omitted passing by reference technique
Submitted: 2012-06-25 09:30 UTC Modified: 2012-06-25 10:18 UTC
From: renwooller at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-06-25 09:30 UTC] renwooller at gmail dot com
Description:
------------
The page describing how to pass variables by reference 
(http://my.php.net/manual/en/language.references.whatdo.php)
 doesn't mention another technique of passing by reference which is to put the 
ampersand on the variable when the function is being called, rather than in the 
function definition.

As a result, I'm not sure what the intended behaviour is eg:

Could it cause a problem?
Perhaps it's some side-effect of being able to declare arrays by reference that 
wasn't intended?
Perhaps it is a handy tool? 

The documentation should mention it and clarify.

Test script:
---------------
<?php
$a = 0;
testRef($a);
echo "no ref :    $a \n";
$a = 0;
testRef(&$a);
echo "input ref : $a \n";
$a = 0;
testRef($a);
echo "function definition ref :  $a \n";
$a = 0;
testRef(&$a);
echo "function definition and input ref :  $a \n";
function testRef($a) {
    $a +=1;
}
function testRef2(&$a) {
    $a +=1;
}
?>

Expected result:
----------------
I don't know, that's the problem with the documentation. Maybe 'input ref' should 
actually be 0?

Actual result:
--------------
no ref : 0 
input ref : 1 
function definition ref : 0 
function definition and input ref : 1 

Patches

pass-by-reference-at-function-invocation (last revision 2012-06-25 09:37 UTC by renwooller at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-25 10:18 UTC] nikic@php.net
This is called call time pass by reference and was deprecated in PHP 5.3 and subsequently removed in PHP 5.4.

There is a small note about it in http://my.php.net/manual/en/language.references.pass.php. I don't think that any further mention is necessary as this feature no longer exists.
 [2012-06-25 10:18 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 09:00:02 2026 UTC