Hello Ray,

Thursday, June 17, 2004, 3:23:10 PM, you wrote:

> I understand your point, however, this is the way that other languages 
> behave and its a feature that i consider to be very necessary and 
> timesaving.

In this case PHP behaves like Java very only one pass by reference
is allowed.

You compare this to C++ and others where pointers exist. And obviously
you can set a pointer to NULL.

BUT we are talking of pass by reference or pass by value since a PHP
pointer is a '$$name' construct.

> My understanding was that Typehinting exists to save having 
> to do such if-else clauses all the time, since 99.9% of the time, you 
> will expect an object of a certain class or nothing at all.

Exactly. And i don't want to have to write
function bla(Classname $x) { if (!is_null($x))....
all the time.

> The problem 
> here is that i need only to know that an argument is either an instance 
> of a class or null, nothing else, but removing the typehinting 
> effectively means any argument can be passed, and its not longer 
> enforced at a PHP level, but within my own code... and since this is 
> something that happens a lot, it seems a shame to loose this handy, 
> timesaving functionality.

I don't think it is timesaving to have to write '!is_null()' all the time.

And once again null is not an instance of any class.

Last but not least we know already that a lot of people like to
be able to handle both instanceof or null with typehints. But at
the moment we have no solution that can go into PHP 5.0. However
i am quite sure we will address this for 5.1.

> Ray


> and Marcus Boerger wrote:

>>Hello Ray,
>>
>>Wednesday, June 16, 2004, 4:26:26 PM, you wrote:
>>
>>  
>>
>>>Hi all,
>>>    
>>>
>>
>>[....]
>>
>> - NOTHING stops you from passing NULL to functions.
>> - Typhints are a shortcut for an 'instanceof'`test
>>
>> - now try NULL instanceof stdclass:
>>
>>php-cvs $ php -r 'var_dump(NULL instanceof stdclass);'
>>bool(false)
>>
>>- what you probablywant is
>>function bla($x) {
>>  if (is_null($x)) {
>>    // handle null
>>  } else if ($x instanceof whatever) {
>>    // handle instance
>>  } else {
>>    // handle error
>>  }
>>}
>>
>>- if you look again you'll see that you are doing *three different*
>>  things in your code. Typehints have a different usage!
>>  
>>best regards
>>marcus
>>
>>  
>>




-- 
Best regards,
 Marcus                            mailto:[EMAIL PROTECTED]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to