Skip to content

[Bug]: isset() on a static property no longer compiles: "Cannot use isset() on the result of an expression" #101

Closed

Description

@fdaviddpt

Bug report

When a class uses isset(self::$prop) on a static property, the rewritten file does not compile:

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in src/Holder.php on line 11

It happens with or without a docblock on the property, and also with inline_vars.properties => false. We hit it on a common memoisation pattern (if (!isset(self::$cache)) { self::$cache = ...; }) and it takes the whole test run down, since it is a compile error.

Two files plus composer.json, default config (no typephp.php):

composer.json

{"require": {"typephp/typephp": "0.10.26"}}

src/Holder.php

<?php

namespace App;

class Holder
{
    private static ?string $name = null;

    public function get(): string
    {
        if (!isset(self::$name)) {
            self::$name = self::class;
        }
        return self::$name;
    }
}

run.php

<?php

require __DIR__ . "/vendor/autoload.php";
require __DIR__ . "/src/Holder.php";

echo (new App\Holder())->get(), " OK\n";
Variant Result
isset(self::$name), static property, no docblock Fatal error
same, with `/** @var class-string null */` on the property
same, with inline_vars.properties => false Fatal error
isset(self::$cache['k']) on a static array OK
isset($this->name) on an instance property OK
TYPEPHP_DISABLE=1 OK

Tested on v0.10.26 and on main (88fcb12), PHP 8.2 and 8.3. The type cache was cleared before each run.

Code snippet that reproduces the problem

No playground link: the snippet above is complete.

Expected output

App\Holder OK

Context: same large codebase as #93 / #99; this one stopped a whole module's test suite in CI.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingnext minor releasefeature for next minor release

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions