php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24462 alternate way to call functions with parameters
Submitted: 2003-07-02 12:15 UTC Modified: 2003-07-02 13:02 UTC
From: waxmop at sarcastic-horse dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.2 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 28 = ?
Subscribe to this entry?

 
 [2003-07-02 12:15 UTC] waxmop at sarcastic-horse dot com
Description:
------------
<pre>

If I have a function like this:

<?php
function foo($v1='aaa', $v2='bbb', $v3='ccc', $v4='ddd')
{
?>
<p>v1 is <?=$v1?></p>
<p>v2 is <?=$v2?></p>
<p>v3 is <?=$v3?></p>
<p>v4 is <?=$v4?></p>
<?php
}
?>

If I want to override the values for $v2, and $v4, I've gotta list all the parameters after v1.

In python, if I had the same function:

def foo(v1='aaa', v2='bbb', v3='ccc', v4='ddd'):
    print "v1 is ", v1
    print "v2 is ", v2
    print "v3 is ", v3
    print "v4 is ", v4
#end foo definition

And I wanted to override the vars, I could call the function like this:

foo(v2='xxx', v3='zzz');

But this isn't possible in PHP.  The python way allows for more obvious self-documenting code.  Is there any chance this could get added?

</pre>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-02 13:02 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

Already proposed in some other report. And no, this will not be supported either.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 11 11:01:31 2024 UTC