From: stormbyte at gmail dot com
Operating system: Linux
PHP version: 5.4.11
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:Pass arrays as reference by default
Description:
------------
One of major benefits from PHP is that it is very close to C/C++ style, so
it is its functions and coding style (very similar for, while and those
constructs) so if you come from C/C++ world, you have it easy.
To keep this consistence I suggest, as well as C/C++ does, passing arrays
as reference in function arguments by default, or at least an option to
behave like that.
For me, it does not make much sense to "follow" C/C++ coding styles and
behaviour, while not following that behaviour.
Furthermore, objects are already passed by reference as default, so why not
arrays? IMHO I think that inconsistence may confuse programmers.
Test script:
---------------
function foo($arr) {
array_push($arr, "test");
}
function bar(&$arr) {
array_push($arr, "test");
}
$a=array();
foo($a);
//$a is empty
bar($a);
//$a[0]="test"
Expected result:
----------------
To be consistent with the rest behaviour of "imitating" C/C++ and pass
arrays as reference automatically as well as objects are.
Also, it may be a performance gain by doing that (which is one of the
reasons in C world it is that way)
--
Edit bug report at https://bugs.php.net/bug.php?id=64266&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=64266&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=64266&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=64266&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64266&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64266&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64266&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64266&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64266&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64266&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64266&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=64266&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=64266&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64266&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64266&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64266&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64266&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64266&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64266&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64266&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64266&r=mysqlcfg