Doc #62406 [NEW]: Omitted passing by reference technique
| From: | renwooller at gmail dot com | Date: | Mon, 25 Jun 2012 09:30:14 +0000 |
| Subject: | Doc #62406 [NEW]: Omitted passing by reference technique | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-8502@lists.php.net to get a copy of this message | ||
From: renwooller at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Omitted passing by reference technique
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
--
Edit bug report at https://bugs.php.net/bug.php?id=62406&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62406&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62406&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62406&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=62406&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62406&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=62406&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=62406&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=62406&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=62406&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=62406&r=support
Expected behavior: https://bugs.php.net/fix.php?id=62406&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=62406&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=62406&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=62406&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62406&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62406&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=62406&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=62406&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=62406&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=62406&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=62406&r=mysqlcfg