At 01:57 PM 5/9/2004 +0300, Stanislav Malyshev wrote:
AG>>>AG>>nullable MyClass $a = 5
AG>>>
AG>>>I must be missing something, but why typehinted variable should have any
AG>>>default except for null anyway? If someone says "I want only MyClass
AG>>>here!", why he should be able to put 5 there?
AG>>
AG>>Well maybe it's a bad example but he can put NULL instead of 5.

Well, that was exactly my point, though not expressed explicitly:
if you can put null there, you don't need 'nullable'. If you say 'MyClass
$a', it doesn't allow null, if you say 'MyClass $a = null', it allows
null. Or, other way around, if you say 'nullable MyClass $a', it defaults
to null, otherwise it has no default. I think we should prohibit to put
any default to typehinted variables except null in any case - since it
doesn't make any sense except promoting code based on is_object checks
etc. - the exact thing we wanted to avoid with typehints.

I think it makes sense not to allow default initialization of non-NULL values when there's a class type hint.


Andi

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



Reply via email to