Sorry, won't work.

I generally go

function blah($obj = null) {
        if (is_null($obj))
                $obj = new ArgumentObject();

        ... do something...
}

I think you can also use:

function blah(ArgumentObject $obj = null) {

}

Just to make sure what you're getting is an ArgumentObject if  
anything is provided...

Steve

On 12/09/2008, at 11:06 AM, Philip Arndt wrote:

>
> Hi,
>
> Has anybody had any experience with writing a function that takes an
> optional parameter (a parameter with a default value) that is a
> complex object? Can this be done or is it just primitive types?
>
> For example, the following function works:
>
> function do_something( $args=array() )
> {
>       // do something
> }
>
> whereas this function does not appear to work..
>
> function do_something( $args = new ArgumentObject() )
> {
>       // do something
> }
>
> Am I trying to achieve the impossible?
> And yes, I am aware that the PHP manual page says scalar values..  
> ( http://nz.php.net/manual/en/functions.arguments.php
>   ) but I wondered whether anybody has achieved what I am after :-)
>
> Thanks,
>
> Phil
>
> >


--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to