Req #70296 [NEW]: pass by reference: switch back to call time
| From: | o dot rijkers at gmail dot com | Date: | Tue, 18 Aug 2015 23:41:44 +0000 |
| Subject: | Req #70296 [NEW]: pass by reference: switch back to call time | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-195315@lists.php.net to get a copy of this message | ||
From: o dot rijkers at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Unknown/Other Function
Bug Type: Feature/Change Request
Bug description:pass by reference: switch back to call time
Description:
------------
In the latest version the pass by reference is moved to the function
declaration:
function myFunct(&$arg) {...}
This results in several limitations:
1. the $arg argument can only be a call by reference.
The pass by reference requirement may be dependent of the location
where
the function is called (I just run into this, hence this request),
i.e.
sometimes I just want to call myFunc($a); and I don't want $a to be
changed.
2. it is not possible to pass an expression or literal as the first
argument.
3. it is not possible to define a default value (other than null) and
omit the
argument when calling the function, e.g. myFunc();
It should never be the responsibility of a function to enforce a pass by
reference. At best it could provide the option of a pass by reference
argument. This greatly improves the flexibility, especially for library
developers.
Test script:
---------------
function myFunc(&$arg = 1) {}
function yourFunc($arg) {}
myFunc($a); // no pass by reference as it is not desired
myFunc(3); // no pass by reference as it is not desired
myFunc(); // no pass by reference as it is not desired
myfunc(&$a); // pass by reference as it is required by the caller and
// the option of pass by reference is provided by the
function
yourFunc(&$a); // no pass by reference as this option is not provided by
the
// function declaration
--
Edit bug report at https://bugs.php.net/bug.php?id=70296&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70296&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70296&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70296&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70296&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70296&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70296&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70296&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70296&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70296&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70296&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70296&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70296&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70296&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70296&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70296&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70296&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70296&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70296&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70296&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70296&r=mysqlcfg