Re: 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]

 



Daevid Vincent wrote:
> 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...
> 
 > 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?!? :-(
> 


What you are wanting to do is not possible.

Back in the day, I worked on a project that used our own variation of this type of functionality.

We had this function that helped a little


function alternate(&$a, $b) {
	return $a = ( $a ? $a : $b );
}



function query($sql, $params=array()) {
	alternate($params,	array());
	extract($params);

	alternate($parameters,	null);
	alternate($showSQL,	false);
	alternate($showErrors,	true);
	alternate($execute,	true);
	alternate($noHTML,	false);
	alternate($profile,	0);

	# Do your thing...

}

This allowed for us to include/exclude whatever we wanted from the

it is a little long winded to get to what you are looking for ( I think )


But it worked for us.




-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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