Re: [RFC][Vote] Typed Properties

From: Date: Wed, 25 May 2016 19:43:32 +0000
Subject: Re: [RFC][Vote] Typed Properties
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.internals 
Request: Send a blank email to internals+get-93527@lists.php.net to get a copy of this message
On 25 May 2016 at 21:13, Niklas Keller <me@kelunik.com> wrote: > Unset can reset it to the default value, but wiping type information is > probably > not an option here. > Wiping type info is indeed unwanted. As it currently stands, for example, un-setting a property and then re-assigning it retains its visibility properties, and doesn't destroy property information. See https://3v4l.org/pCmTV for an example (copied here for reference): <?php class Foo { private $bar = 'baz'; public function __construct() { unset($this->bar); } public function getFooBar() { return $this->bar; } } class Bar extends Foo { private $bar = 'baz'; public function __construct() { parent::__construct(); unset($this->bar); } public function getBarBar() { return $this->bar; } } $bar = new Bar(); var_dump($bar->getFooBar()); // notice + null var_dump($bar->getBarBar()); // notice + null $rBarBar = new ReflectionProperty(Foo::class, 'bar'); $rBarBar->setAccessible(true); $rBarBar->setValue($bar, __LINE__); var_dump($bar->getFooBar()); // line no. var_dump($bar->getBarBar()); // notice + null Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#93527) next »