[PHP] Empty Reference to an Object

2004-01-13 Thread Sebastian Ossio
Hi,

I´m trying to give an empty reference as a parameter, in a function. Or 
rather make a parameter that is a reference optional.

I have a function that should react differently if it is given an object 
or not. It works, but it gives me a warning that the second argument is 
not being given obviously.

Sadly I cannot make the parameter optional in the function definition 
because mine has to be a reference. One can´t do such a thing as

function( $parameter1,  objectparameter = NULL)

this results into a parsing error.

I cannot believe that there is no way of making an object parameter 
optional.

So tell me please what I´m missing.

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


Re: [PHP] Empty Reference to an Object

2004-01-13 Thread Richard Davey
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.

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

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



Re: [PHP] Empty Reference to an Object

2004-01-13 Thread Jimmy Lantz
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,
 Richardmailto:[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Empty Reference to an Object

2004-01-13 Thread Ford, Mike [LSS]
On 13 January 2004 15:10, Sebastian Ossio wrote:

 Hi,
 
 I´m trying to give an empty reference as a parameter, in a
 function. Or
 rather make a parameter that is a reference optional.
 
 I have a function that should react differently if it is
 given an object
 or not. It works, but it gives me a warning that the second
 argument is
 not being given obviously.
 
 Sadly I cannot make the parameter optional in the function definition
 because mine has to be a reference. One can´t do such a thing as
 
 function( $parameter1,  objectparameter = NULL)
 
 this results into a parsing error.
 
 I cannot believe that there is no way of making an object parameter
 optional. 
 
 So tell me please what I´m missing.

PHP5 ;).  This is one of the improvements that will be in PHP 5 when it is
released.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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