Re: Empty reference parameter
| From: | Tom Rogers | Date: | Tue, 13 Jan 2004 15:28:11 +0000 |
| Subject: | Re: Empty reference parameter | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-174451@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, January 14, 2004, 1:10:53 AM, you wrote:
SO> Hi,
SO> I´m trying to give an empty reference as a parameter of a function. Or
SO> rather, make a parameter that is a reference optional.
SO> I have a function that should react differently if it is given an object
SO> or not. It works, but it gives me a warning that the second argument is
SO> not being given obviously.
SO> Sadly I cannot make the parameter optional in the function definition
SO> because mine has to be a reference. One can´t do such a thing as
SO> function( $parameter1, & objectparameter = NULL)
SO> this results into a parsing error.
SO> I cannot believe that there is no way of making an object parameter
SO> optional.
SO> So tell me please what I´m missing.
Try doing it in 2 steps
$ref = false;
function test(&$var)
if(is_object($var)){
echo "object passed";
}
}
test($ref);
$ref =& new object;
test($ref);
--
regards,
Tom