Php-language-server: `new static::$classNameA()` should not be an error

Created on 25 Sep 2017  路  5Comments  路  Source: felixfbecker/php-language-server

new static::$classNameA(); is detected as an error.
It reports ';' excepted.

But new self::$classNameA(); is ok.

I think new static::$classNameA(); should not be detected as an error.

Example code:

<?php
namespace App;

class Test
{
    protected static $classNameA = A::class;
    protected static $classNameB = B::class;

    public function a()
    {
        $a = new static::$classNameA();
        $a->output();
    }

    public function b()
    {
        $b = new self::$classNameB();
        $b->output();
    }
}

2017-09-25 22 08 34

bug

Most helpful comment

All 5 comments

@roblourens

<?php
if (static::$instance instanceof static) {
    return true;
}

This will also report an error.

If you want something to test against:
https://github.com/silverstripe/silverstripe-framework/blob/3.6/dev/Log.php#L94

file: 'file:///c%3A/Users/jake/www/projects/ptv-mpw/htdocs/framework/dev/Log.php'
severity: 'Error'
message: '';' expected.'
at: '94,32'
source: 'php'

This has now been fixed in Microsoft/tolerant-php-parser#194 :)

Was this page helpful?
0 / 5 - 0 ratings