On 5/25/2016 9:13 PM, Niklas Keller wrote: > 2016-05-25 20:39 GMT+02:00 Fleshgrinder <p...@fleshgrinder.com>: > >> In my opinion it should simply vanish along with its definition. I mean, >> > > Usually, yes. But suddenly `private Type $foo` isn't reliable anymore if > unset is supported for typed properties, because the following would just > remove all type info / enforcement: > > $backup = $this->foo; > unset($this->foo); > $this->foo = $backup; > > Unset can reset it to the default value, but wiping type information is > probably > not an option here. > > Regards, Niklas >
I had to check because I never tried this once in my life (why would one need it anyways) ... class A { private $foo = "foo"; function get() { return $this->foo; } function unset() { unset($this->foo); } } $a = new A; echo $a->get(); // foo $a->unset(); echo $a->get(); // Notice: Undefined property: A::$foo $a->foo = "foo"; // Fatal error: Uncaught Error: Cannot access private property A::$foo In other words, unset is not really unset already! QED: Preserving *all* attributes of a property is the only consistent way. However, preserving its value is not. I do not think that there is a problem together with the typed properties, nullability, and unset simply because the property is not explicitly assigned null by unset, it is being undefined. I think internally null is actually assigned and it's not IS_UNDEF, right? However, from a userland perspective it is definitely not defined anymore and access should (as it does) result in an error (in our case E_INFO) plus null is being returned but only because undefined does not exist in PHP userland. I did not read up on all the history yet but I am on it ... -- Richard "Fleshgrinder" Fussenegger
signature.asc
Description: OpenPGP digital signature