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).
class a {
function b(Obj c=null) {};
}
$a->b(null) or $a->b($anything_not_an_Obj) would be an error.
$a->b() would be valid.
function Format(ZIFormatter $formatter=null)
{
if (isset($formatter))
return $formatter->Format($this);
else return $this;
}
Now the argument can be made to not type hint $formatter to begin with, but
I don't want to have to check that it isnt null and instanceof ZIFormatter
interface. I just want to know if it was passed, that I can use it as a
ZIFormatter object.
Bob Silva
-----Original Message-----
From: Cristiano Duarte [mailto:[EMAIL PROTECTED]
Sent: Saturday, October 16, 2004 12:14 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DEV] Type hints with null default values
Hi @ll,
Now that 5.0.3 is out, maybe it's time to bring back that
old problem left in May: type hints and null default values.
This feature was dropped since no one could come with a
reasonable solution.
So, for now, there is no (engine) way to have a parameter that
can only be of some class or null. Am I right ?
The use of null (I know it's not a value it's a type...) is
justified because we don't have a "value" to represent
a NULL OBJECT(or NO OBJECT).
IMO, this is a necessary feature (maybe others thing this way
too) and that's why I brought it back.
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