Re: optional object arguments to a function

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

 



Shawn McKenzie wrote:
Michael A. Peters wrote:
Rene Veerman wrote:
On Sat, Feb 13, 2010 at 9:05 AM, Michael A. Peters <mpeters@xxxxxxx>
wrote:
How do I specify a default null object, or otherwise make the argument
argument optional?

To my knowledge: can't be done.

But you can check any args through the func_get_arg*() functions, then
per-parameter push 'm through a check function that checks if their
primary properties are set.
It's equivalent to checking for null ( / bad) objects.

Thank you to everybody. I think I will see how far I can get with
func_get_arg - it may solve the problem.

The other hackish solution I thought of is to put the object arguments
into a key/value array and pass the array as a single argument to the
function. That way I can check for the key and if the key is set, grab
the object associated with it.

Maybe I mis-read your post, but what's wrong with Jochem's method.
That's what I was going to propose.


Possibly nothing - but passing an array with keys I think makes it easier to determine what the object (a DOM node) corresponds with by just looking at the key (IE for a single integral there can be lower limit, upper limit, etc.)

Maybe after implementing it that way and actually getting things working, I can look into passing the dom objects as actual arguments instead of wrapping them in array.

But some existing functions like tidy take some of their optional arguments in a key->value array and it is now in php core so it isn't unprecedented to use a key->value array.

--
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