# Type hints with null default values

- Thread: https://externals.io/message/13348
- Original archive: https://news-web.php.net/php.internals/13348
- Started by Cristiano Duarte on 2004-10-16T19:13:51+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13348 — Cristiano Duarte — 2004-10-16T19:13:51+00:00

URL: https://externals.io/message/13348#13348

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

---

## #13349 — Georg Richter — 2004-10-16T21:16:03+00:00

URL: https://externals.io/message/13348#13349 · In reply to: #13348

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

---

## #13350 — Markus Fischer — 2004-10-16T21:24:59+00:00

URL: https://externals.io/message/13348#13350 · In reply to: #13348

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

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

---

## #13351 — Robert Silva — 2004-10-16T21:50:58+00:00

URL: https://externals.io/message/13348#13351 · In reply to: #13348

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

---

## #13352 — Cristiano Duarte — 2004-10-16T22:00:52+00:00

URL: https://externals.io/message/13348#13352 · In reply to: #13351

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

---

## #13353 — Cristiano Duarte — 2004-10-16T22:01:51+00:00

URL: https://externals.io/message/13348#13353 · In reply to: #13349

Georg Richter wrote:

> Am Sa, den 16.10.2004 schrieb Cristiano Duarte um 21:13:
> > […]
> 
> 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
