php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47331 use a function's default arguments but change one of the end ones in the list
Submitted: 2009-02-06 20:22 UTC Modified: 2016-12-01 13:40 UTC
Votes:9
Avg. Score:4.6 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:5 (55.6%)
Same OS:7 (77.8%)
From: daevid at daevid dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: 5.2.9RC1 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daevid at daevid dot com
New email:
PHP Version: OS:

 

 [2009-02-06 20:22 UTC] daevid at daevid dot com
Description:
------------
Request a way to use the default values of a function without
specifying every single one until the parameter you want to modify.

The concept is simple, just specify which parameters in the function call you want to change and leave the others as their default.

So given a function that takes seven parameters, I want to change one (or more) of them and leave the other defaults alone without specifically re-defaulting each value (which assumes I even know what each default value is to begin with)

Bug #2285 is similar, but passing an array is a hack and not acceptable. It will not help in an IDE setting to see foo(array) and not know which key/values the hash expects.

Bug #20544 is also close, but I don't agree with using "->" or "=>" either. it should just be "=" as illustrated below.

Bug #24153 is also similar, but using "," as place holders seems a little hacky too and difficult to read. Plus who wants to count empty place holders to figure out which parameter is being set?

Reproduce code:
---------------
function SQL_QUERY($sql, $parameters = null, $showSQL = false,
$showErrors = true, $execute = true, $noHTML = false, $profile = 0)
{
        var_dump($sql, $parameters, $showSQL, $showErrors, $execute, $noHTML, $profile);
}

SQL_QUERY('SELECT * FROM foo WHERE bar = ?', array('beep'), $execute=false);

The above function call doesn't error out on me, it just seems it
doesn't do anything either :-\

Expected result:
----------------
string(31) "SELECT * FROM foo WHERE bar = ?"
array(1) {  [0]=>  string(4) "beep" }
bool(false)
bool(true)
bool(true)  <-- I would have expected this one to be bool(false)
bool(false)
int(0)

Actual result:
--------------
So it seems I have to do this verboseness (AND know what the default
values are to begin with too):

SQL_QUERY('SELECT * FROM foo WHERE bar = ?', array('beep'), false, true,
false, false);

Just to change one default parameter near the end?!? :-(

-------------------------------

P.S. this PHP bug report form made me choose a PHP version to submit this, even though I picked "irrelevant" I had to then choose 5.2.9rc1 just to submit :-\

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-06 21:42 UTC] ryanrray at gmail dot com
You should be able to call out any param explicitly.
 [2016-12-01 13:40 UTC] cmb@php.net
-Status: Open +Status: Suspended -Package: Feature/Change Request +Package: *General Issues
 [2016-12-01 13:40 UTC] cmb@php.net
This language change would require the RFC process[1], and as such I'm suspending this ticket for the time being. Note that there is already a very similar RFC in discussion phase[2]. Note also that your suggestion to use = in the function call would cause an ambiguity, i.e. a BC break at least.

[1] <https://wiki.php.net/rfc/howto>
[2] <https://wiki.php.net/rfc/named_params>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC