Technically valid PHP code causes fatal error
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.
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...
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 I started to work on phpsa, possible will try to release ASAP after big changes!