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
Am Sa, den 16.10.2004 schrieb Cristiano Duarte um 21:13:
Hi @ll,
Now that 5.0.3 is out
Doohh 5.0.3? I didn't see any announcement and I planned to commit
several stuff before :(
/Georg
Georg Richter, Senior Software Developer
MySQL AB, www.mysql.com
See you at MySQL ComCon Europe November 8-10!
www.mysqlcomconeurope.com
Georg Richter wrote:
Am Sa, den 16.10.2004 schrieb Cristiano Duarte um 21:13:
Hi @ll,
Now that 5.0.3 is out
Doohh 5.0.3? I didn't see any announcement and I planned to commit
several stuff before :(
Sorry Georg. I meant: Now that 5.0.2 is out...
Cristiano Duarte
Cristiano Duarte wrote:
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
aNULL
OBJECT(or NO OBJECT).
IMO, this is a necessary feature (maybe others thing this way
too) and that's why I brought it back.
I'm also realing waiting for this implemented. Since I've started to use the new features of v5, I've had to deal with parameter checks in exactly this way. If it's not class/interface instanceof type x, throw an exception. I just hope, if it gets implemented, it's done via exceptions too.
- Markus
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:cunha17@uol.com.br]
Sent: Saturday, October 16, 2004 12:14 PM
To: internals@lists.php.net
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
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 aNULL
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