Robert Silva wrote:

> PHP doesn't have a concept of a "null" reference though. So to say that
> every other language allows it is not a valid argument. The other
> languages allow it because the language supports it. And that seems to be
> what the arguments against it centered around.
> 
> I think a compromise would be to allow the argument to be optional but
> still enforce the type hint. What this doesn't address fully is multiple
> optional type hinted arguments.
> 
> function A(ZObj $arg2=null, ZObj $arg3=null) {}
> 
> How would you pass $arg3 if you didn't have anything to pass for $arg2.
> Maybe that's just an inherent restriction of the language...to pass $arg3,
> you have to pass a ZObj as $arg2.
Since PHP doesn't support explicit method overloading, we should support
some form of telling the function that $arg2 wasn't passed. This problem can
be solved with named parameters instead os positional ones, but someone
suggested it a long ago and, at that moment, it would not be feasible.

> 
> Someone else suggested adding null references to the language:
> 
> ZObj $obj = null;
> 
> But I don't think that is the right solution either not to mention the
> nightmare of actually implementing it.
It was supported before(until May), isn't it ? 


IMHO, what we have now is "not null typehints" so what's the matter if we
accept "not null typehints" when we have this construction:

function A(ZObj $arg2, ZObj $arg3) {}

and "null typehints" with this:

function A(ZObj $arg2=null, ZObj $arg3=null) {}

as we supported before(except that with the first construction nulls are not
allowed). Maybe I'm "blind" but I can't see the problem that Marcus pointed
anymore. If I can remember, he wants a way to enforce typehints not
allowing nulls: construction-1 does it.
I really need optional typehints and construction-2 supports it.
IMHO, everybody would be happy. 
Any comments ?

Regards,

Cristiano Duarte

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

Reply via email to