Req #70296 [Opn->Wfx]: pass by reference: switch back to call time
| From: | rasmus@php.net | Date: | Wed, 19 Aug 2015 00:32:45 +0000 |
| Subject: | Req #70296 [Opn->Wfx]: pass by reference: switch back to call time | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195317@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70296&edit=1
ID: 70296
Updated by: rasmus@php.net
Reported by: o dot rijkers at gmail dot com
Summary: pass by reference: switch back to call time
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Unknown/Other Function
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Latest version? This was changed in PHP 5.3.0 in 2009. There are a number of reasons why it needs to
be this way, sorry.
Previous Comments:
------------------------------------------------------------------------
[2015-08-18 23:41:41] o dot rijkers at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=70296&edit=1