Req #47331 [Opn->Sus]: use a function's default arguments but change one of the end ones in the list

From: Date: Thu, 01 Dec 2016 13:40:55 +0000
Subject: Req #47331 [Opn->Sus]: use a function's default arguments but change one of the end ones in the list
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205713@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=47331&edit=1 ID: 47331 Updated by: cmb@php.net Reported by: daevid at daevid dot com Summary: use a function's default arguments but change one of the end ones in the list -Status: Open +Status: Suspended Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues PHP Version: 5.2.9RC1 Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [2009-02-06 21:42:14] ryanrray at gmail dot com You should be able to call out any param explicitly. ------------------------------------------------------------------------ [2009-02-06 20:22:17] 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 :-\ ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=47331&edit=1

« previous php.bugs (#205713) next »