Re: Empty Reference to an Object

From: Date: Tue, 13 Jan 2004 15:24:57 +0000
Subject: Re: Empty Reference to an Object
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-174450@lists.php.net to get a copy of this message
At 16:14 2004-01-13, you wrote:
Hello Sebastian, Tuesday, January 13, 2004, 3:09:39 PM, you wrote: SO> I cannot believe that there is no way of making an object parameter SO> optional. function ($parameter1, $parameter2 = NULL) { // etc } If passed to your function, $parameter2 will be your object (or string or whatever you wanted), if not passed in it'll be null. this might work this is an ugly solution from the top of my head, not tested:
<?php $myObject =& (ifYour object exists)? $yourObject : new stdClass; foo("blaha",&$myObject); function foo($para1,&$param2){
        if(get_class($param2) =='stdClass') $param2 = NULL; // get_class might return stdclass not sure
} ?> / Jimmy
-- Best regards,
 Richard                            mailto:rich@launchcode.co.uk
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#174450) next »