The issues surrounding this seemed to have been muddied up a little, I'll
try to clear them up.

I see two different sets of functionality that people are asking for.

#1. The ability to pass null on a type hinted param (but still a mandatory
param)

#2. The ability to define an optional type hinted param.

I see it as a very important distinction to make. Using the #2 to solve #1
is not the solution PHP should implement. Using some method which operates
on the class hint itself is the right solution.

For example, using the [] method:

public function Compare([BaseClass] $objA, $cmpFunc);

If we were to use the optional parameter method to solve #1, then you limit
the language unnecessarily.

public function Compare(BaseClass $objA=null, $cmpFunc); <-- Error!

That would be a mistake, IMO, to put that restriction on the language.

Thanks for all the feedback you guys are providing, together we should be
able to come up with a solution that meets everyones needs.

Bob Silva


-----Original Message-----
From: Marcus Boerger [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 19, 2004 11:23 AM
To: Christian Schneider
Cc: [EMAIL PROTECTED]; Andi Gutmans; Robert Silva; 'Cristiano Duarte'
Subject: Re: [PHP-DEV] Type hints with null default values

Hello Christian,

  we've discussed this restriction before and the more i think over the
issue the more i come to the conclusion that if at all we should provide
this exact syntax.

regards
marcus

Tuesday, October 19, 2004, 11:42:22 AM, you wrote:

> Andi Gutmans wrote:
>> So one suggestion (also made a few months ago) was that the following:
>> function method(MyClass $obj = NULL);
>> would mark $obj as allowing NULL parameter.

> The only restrictions I see is that it makes the parameter optional as 
> well (something I don't consider a problem as it is probably desirable 
> in most cases anyway to be able to leave out an explicit null) and that 
> it only works if no mandatory parameter follows, e.g.
> function method(MyClass $obj = null, $mandatory);
> is not possible. Not a real problem either IMHO.

> I still like this option more than anything else proposed here because 
> it doesn't add new syntax and is simple to understand ("I can leave the 
> parameter out then it will be null or I can pass null as I could also 
> have left it out instead, otherwise I need to pass an object of MyClass").

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

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

Reply via email to