Hi,

On Thu, Mar 17, 2016 at 8:46 PM, Andrey Andreev <n...@devilix.net> wrote:
> I'd support borrowing the "?" nullable annotation from HackLang for
>> people who want a less strict behavior:
>>
>> public ?string $name;
>>
>> This means that $name can either be a string or the NULL value.
>>
>
> Or, do it like with parameter type hinting:
>
>      public string $name = null;
>
> Although I'm all for limiting NULL to only being the default value:
>
>     $this->name = null; // this should throw a TypeError

NULL is special type. '' and NULL is different entity.

class User {
  public string $username = NULL;
}

After authentication $username could be "yohgaki". What is should be
after logout? $username = '' does not make sense, but $username =
NULL.

There are ways to work around this, but property cannot be NULL is
problematic. IMO.

class User {
  public string|null $username = NULL;
}

may work. I'm not sure if this is good idea in general.

Regards,

--
Yasuo Ohgaki
yohg...@ohgaki.net

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

Reply via email to