Re: Non-nullable properties
| From: | Rowan Collins | Date: | Mon, 16 Jul 2018 15:59:25 +0000 |
| Subject: | Re: Non-nullable properties | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102854@lists.php.net to get a copy of this message | ||
On 16 July 2018 at 16:42, Marco Pivetta <ocramius@gmail.com> wrote:
> There are naturally 3 states in the engine:
>
> 1 - value set
> 2 - value not set (default
null)
> 3 - undefined/uninitialised
>
> These have been around since 5.0 AFAIK.
>
"Undefined" and "uninitialised" are not the same state:
class A {
public $alpha = 42;
public $beta;
// no such property as $charlie;
public SomeClass $delta;
}
$a = new A;
$a->alpha; // value set
$a->beta; // value not set (default null)
$a->charlie; // undefined, but still accessible, with implicit value null
$a->delta; // uninitialised; all attempts to access will throw an error
The behaviour of $a->charlie is consistent with other undefined variables
(e.g. a local variable can be read before it is written to). I can't think
of anything in the language which behaves the same way as $a->delta.
Regards,
--
Rowan Collins
[IMSoP]