How can I use a function's default arguments but change one of the end ones in the list?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?!? :-(



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux