On 4/7/2016 8:21 PM, Dmitry Stogov wrote: > Today, PHP works with arguments in this way. > If we decide to enable nullable "?" syntax and/or "union types" we will > have to use them for properties as well. > but for now, we don't have anything accepted yet, and we are going to > push both RFC on next week. >
I know, I just wanted to clarify it. >> >> class StupidExample { >> private int? $x = 42; >> >> public function setX(int? $x = 42) { >> $this->x = $x; >> } >> } >> >> $o = new StupidExample(); >> $o->setX(null); >> >> Note how the nullable (union null) type is much more useful than the >> current implementation in PHP. > > I don't see a lot of use cases, but it's not a problem to implement this. > Actually the implementation was proposed more than a year ago. > > https://wiki.php.net/rfc/nullable_types > I also don't see many use cases but it makes the intention of a program clearer and it makes it easier for a compiler to reason. Simply because the assignment *int $x = null* is ambiguous since *null* is not an *int*. The type declaration should always explicitly state legal values so that they can be validated everywhere at all times. -- Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature