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.
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.
Bob
-----Original Message-----
From: Cristiano Duarte [mailto:[EMAIL PROTECTED]
Sent: Saturday, October 16, 2004 3:01 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DEV] Type hints with null default values
Robert Silva wrote:
> I think Marcus B's final comments in the original discussion are right on
> track.
>
> Stab: I voted for NULL type hinted arguments before I voted against them.
>
> The main thing that changed my mind, is that in PHP there is no such thing
> as a NULL object. I came to the conclusion that PHP wasn't broken, my
> programming style/code was.
>
> My opinion is that they should stay as they are now although personally.
>
> Now with that said, I do think there needs to be a method to allow a type
> hinted parameter to be optional (but not necessarily null).
That's what I'm asking for. :-)
I'm not asking for null objects, just an optional parameter that must be an
object or a "null" reference.
All OO languages I've ever programmed had this kind of reference(Java, C++,
Delphi, etc.)
Cristiano Duarte
--
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