|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-08-19 00:32 UTC] rasmus@php.net
-Status: Open
+Status: Wont fix
[2015-08-19 00:32 UTC] rasmus@php.net
[2015-08-19 00:40 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 03:00:01 2025 UTC |
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