Re: [RFC] Alternative typehinting syntax for accessors
| From: | Lars Schultz | Date: | Tue, 08 Jan 2013 09:51:10 +0000 |
| Subject: | Re: [RFC] Alternative typehinting syntax for accessors | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-64667@lists.php.net to get a copy of this message | ||
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.
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.