phpsa icon indicating copy to clipboard operation
phpsa copied to clipboard

Technically valid PHP code causes fatal error

Open garrettw opened this issue 8 years ago • 3 comments

If I have a class that contains something like this:

class Something
{
    // ...
    private static $propOne, $propTwo;
    // ...
}

What happens is that after parsing, the resulting ClassDefinition contains both properties, but only one property statement (named for only $propTwo, incidentally).

So far, this partly seems to make sense, but the problem comes in PHPSA\Compiler\Expression\StaticPropertyFetch::compile() which has the following code:

// ...
if (!$classDefinition->hasProperty($name, true)) {
    // return;
}
$property = $classDefinition->getPropertyStatement($name, true);
if (!$property->isStatic()) { // <<<< LINE 46
    // ...
}
// ...

With the code sample given above, hasProperty() returns true for $propOne, making it skip the first if block. Then, because there is no property statement named for $propOne, calling getPropertyStatement() returns null. So, on line 46, $property is set to null, making the call to isStatic() cause a fatal error.

garrettw avatar Jul 01 '17 01:07 garrettw

What version you are using?

I am trying to get error on snippets:

class Test
{
    private static $propOne, $propTwo;

    public function test()
    {
        self::$propOne++;
        self::$propTwo++;
    }
}

And this

class Test
{
    private static $propOne, $propTwo;
}

Nothing...

ovr avatar Jul 02 '17 09:07 ovr

I'm using the latest release, 0.6.2. As there has been almost 150 commits since then, maybe it's time for a new release.

garrettw avatar Jul 02 '17 17:07 garrettw

@garrettw I started to work on phpsa, possible will try to release ASAP after big changes!

ovr avatar Aug 04 '17 16:08 ovr