2009/2/6 Daevid Vincent <daevid@xxxxxxxxxx> > Is there a way to use the default values of a function without > specifying every single one until the parameter you want to modify in > PHP5 ? > > I don't see it here, but feel this would be very useful indeed. > http://www.php.net/manual/en/functions.arguments.php > > So given a function that takes seven parameters, I want to change one of > them and leave the other defaults alone... > > <?php > 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); > } > ?> > > <pre> > <?php SQL_QUERY('SELECT * FROM foo WHERE bar = ?'); ?> > </pre> > <hr> > <pre> > <?php SQL_QUERY('SELECT * FROM foo WHERE bar = ?', array('beep'), > true); ?> > </pre> > <hr> > <pre> > <?php SQL_QUERY('SELECT * FROM foo WHERE bar = ?', array('beep'), > $execute=false); ?> > </pre> > > outputs: > ----------------------------------------------------------------------- > string(31) "SELECT * FROM foo WHERE bar = ?" > NULL > bool(false) > bool(true) > bool(true) > bool(false) > int(0) > ----------------------------------------------------------------------- > string(31) "SELECT * FROM foo WHERE bar = ?" > array(1) { [0]=> string(4) "beep" } > bool(true) > bool(true) > bool(true) > bool(false) > int(0) > ----------------------------------------------------------------------- > 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) > > The above function call doesn't error out on me, it just seems it > doesn't do anything either :-\ > > 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?!? :-( > > > You could probably create a class and break up the functionality of that function, for somebody reading your code would be hard understanding all that parameters, maybe even for you after a while. -- Alpar Torok