Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Technically valid PHP code causes fatal error #334

Open
garrettw opened this issue Jul 1, 2017 · 3 comments
Open

Technically valid PHP code causes fatal error #334

garrettw opened this issue Jul 1, 2017 · 3 comments
Labels

Comments

@garrettw
Copy link

garrettw commented Jul 1, 2017

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.

@ovr
Copy link
Owner

ovr commented Jul 2, 2017

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...

@garrettw
Copy link
Author

garrettw commented Jul 2, 2017

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.

@ovr
Copy link
Owner

ovr commented Aug 4, 2017

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

@ddmler ddmler added the bug label Dec 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants