Page MenuHomePhabricator

Phan gives false positive PhanRedundantCondition on uninitialized typed property
Open, Needs TriagePublic

Description

Typed and untyped object properties behave differently in PHP when their declaration doesn't include an initial value:

<?php

class C {
    public $untyped;
    public string $typed;
}

$c = new C;
isset( $c->untyped ); // false
isset( $c->typed ); // false
var_dump( $c->untyped ); // NULL
var_dump( $c->typed ); // Fatal error: Typed property C::$typed must not be accessed before initialization

(3v4l)
so it's often important to check if a typed property has been initialized before accessing it. Phan however seems to think isset( $c->typed ) is always true (as seen above, this is not the case), and warns about it.

Upstream task is phan/phan#4720.