From: [EMAIL PROTECTED] Operating system: All PHP version: 4.3.0 PHP Bug Type: Feature/Change Request Bug description: Named Arguments
I know this can be accomplished in other way and also know this has been brought up before, but they are messy and require code from the developer to handle this which seems to go against the php ethos of easy and fast to develop. If named arguments could be passed to functions and actually processed by the php parser, then this would be really great. Especially where function prototypes have default values in them and you only want to set one of them. The proposed syntax would be something like this: function foo ($var1="some value", $var2, $var3="some other value") { // function code } then to call the function would be like this foo (var2:="value for argument 2 only"); This would also be great if this feature would extend to the existing functions in the extensions as well. mail (to:="[EMAIL PROTECTED]", message:="no message", subject:="subject"); This in my opinion makes the function calls more readable in some circumstances, particularly when you have to keep going back to the prototype to figure out what the order of the arguments is. It's kind of self documenting really when you look at code written in this way. Bug #2285: default arguments skipping (http://bugs.php.net/bug.php?id=2285) was filed with a similar suggestion and the solution suggested was to use associative arrays. Becuase it was never explained in any of the other reports as to why this wasn't going to be implemented, why the above not more preferable to have than always have to implement the same code this: function foo ($args) { // Named Argument Checks $var1 = "some value"; $var3 = "some other value"; foreach ($args as $key => $value) { $$key = $value; } // Do function code here } foo (array ("var2"=>"some other value again","var1"=>"variable 1")); Surely forcing developers into using this messy syntax goes against one of the main strengths of php which is simple code that's easy to read, understand and develop. I'm in no wasy saying the above code was hard, just the first example of named arguments seems to fit more into the php way than the second example. If this is to be rejected like the other requests for it, can you please provide a reason why the array method is more preferable? -- Edit bug report at http://bugs.php.net/?id=22216&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=22216&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=22216&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=22216&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=22216&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=22216&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=22216&r=support Expected behavior: http://bugs.php.net/fix.php?id=22216&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=22216&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=22216&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=22216&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22216&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=22216&r=dst IIS Stability: http://bugs.php.net/fix.php?id=22216&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=22216&r=gnused