I think it's an interesting idea (the []).
I have to think about that one, if it's too confusing and if it's better than something like nullable.
BTW, I think it has to be class or NULL. I don't believe any other type should be allowed.


Andi

At 07:09 PM 10/18/2004 -0700, Robert Silva wrote:
Based on the issues you listed, how about:

function Method((MyClass) $obj);
function Method([MyClass] $obj);

Surrounding the class type in () or [] thereby marking it as optional.
Much like you would do when commenting a function to take an optional
parameter.

Bob Silva



-----Original Message-----
From: Andi Gutmans [mailto:[EMAIL PROTECTED]
Sent: Monday, October 18, 2004 6:18 PM
To: Robert Silva; 'Cristiano Duarte'; [EMAIL PROTECTED]
Subject: RE: [PHP-DEV] Type hints with null default values

Hi,

First of all, I think most agree that it'd be nice to be able to distinct
between class instances only, and class instances w/ NULL.
However, the main problem was how to specify this in a way which would be
very easy to understand and without over-complicating PHP (I wouldn't want
to add more complexity to the OO language unless really necessary or we'll
loose the ease of use advantage PHP has).

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 problem with it is that it also means that $obj maybe an optional
argument so we would have some ambiguity here.

I don't like the idea of using other values as the default value like
"false" i.e.:
function method(MyClass $obj = false);
because I think it's very un intuitive of what this means. Actually, we
should update the compiler to make sure to not allow optional parameters if
class type hints are being used (except for maybe NULL if we do give it
some kind of meaning).

All in all I haven't been able to think of a good solution/syntax, old
ideas like "MyClass $obj or NULL" are more or less OK but then you can use
a default parameter so it might become "MyClass $obj or NULL = NULL". Yikes!

Andi

--
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

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



Reply via email to