FAQ
Since there are so many questions about nullable state (the default, in
PHP), would it make sense to enforce nullable types, for now?

Specifically, the current RFC could be simplified until further clarity is
made on how non-nullability behaves:

  * we'd enforce users to always have `private ?Type $foo;` in their
signatures for 7.1
  * we'd allow `private Type $foo;` for 7.2, when the behavior of
non-nullable properties is fully clarified
  * until then, `private Type $foo;` will cause a parser error

I'm just trying to simplify things to get such a feature in, as type
checking on object properties is a huge and very beneficial addition.


Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/
On 25 May 2016 at 19:00, Niklas Keller wrote:


There is a difference between not set and no meaningful value.
In PHP, there's no such difference for properties. And I think we should be
consistent with the existing behavior here.

The former is literally unset(), the latter is null. The only semantics
PHP exposes here is that not set can be upgraded to "no meaningful" value
in form of null with a notice.

The difference thus is quite minor, but semantically important.
Hence to *set* the value, we need to explicitly set null.

If we don't do it this way, we won't have a way to explicitly *set*
nullable properties to a value (null in this case). (without explicit unset
in ctor).

Bob

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2019 Grokbase