From: daevid at daevid dot com Operating system: PHP version: 5.2.9RC1 PHP Bug Type: Feature/Change Request Bug description: use a function's default arguments but change one of the end ones in the list
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 bug report at http://bugs.php.net/?id=47331&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47331&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47331&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47331&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47331&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47331&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47331&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47331&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47331&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47331&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47331&r=support Expected behavior: http://bugs.php.net/fix.php?id=47331&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47331&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47331&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47331&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47331&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47331&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47331&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47331&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47331&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47331&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47331&r=mysqlcfg