Unset static properties
| From: | Benjamin Morel | Date: | Wed, 10 Apr 2019 12:20:16 +0000 |
| Subject: | Unset static properties | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-105204@lists.php.net to get a copy of this message | ||
Hi internals,
I came across this when playing with static properties:
class A {
public static int $x;
}
// This throws, as expected:
// Error: Typed static property A::$x must not be accessed before
initialization
echo A::$x;
// Once we initialize the property:
A::$x = 1;
echo A::$x; // 1
// There is no way to revert the property back to uninitialized state:
// Error: Attempt to unset static property A::$x
unset(A::$x);
Is this expected behaviour? I don't currently have a use case for this, but
am wondering whether it is consistent to disallow un-initializing a static
property when it's allowed to be uninitialized in the first place.
Cheers,
Ben