2013/1/8 Lars Schultz <lars.schu...@toolpark.com>

> Am 08.01.2013 10:03, schrieb Lazare Inepologlou:
>
>> The fact is that the existing syntax for nullable type hinting has its own
>> problems. For example, this is not possible:
>> function foo( Bar $bar = null , $mandatory ) { ... }
>>
>
> Sure it's possible;) I did not get a syntax error for that...I even use
> that case many times in my code exactly for that purpose, to allow $bar to
> be null but require $mandatory to be defined explicitly.
>

Seems you are right. Sorry.


>
>  I would love to have the question mark syntax for both properties and
>> argument type hinting.
>>
>
> Introducing a BC-Break and/or yet another syntax? Is that worth it?
>
>  This does not apply in all cases. Here is an example of a property that is
>> guaranteed not to be null:
>>
>> class Foo {
>>    private $_date;
>>    public DateTime $date {
>>      get {
>>        return is_null($date) ? new DateTime() : $this->date;
>>      }
>>      set {
>>        $this->date = $value;
>>      }
>>    }
>> }
>>
>
> The property is still null;) Only the return value of the getter will not
> be null. But that's not the issue, is it? I am not arguing the case of NOT
> allowing null, Stas wanted to always allow null because of this reason and
> not have a special syntax to declare this.
>
>
>
No, the field $_date can be null. The property $date is not null, cannot be
set to null and cannot return null. Furthermore, it cannot be unset (should
fail with an error) and isset always returns true.


Lazare INEPOLOGLOU
Ingénieur Logiciel

Reply via email to