Repository navigation
Internal error: Undefined class constant 'KIND_SEMICOLON' #1386
Copy link
Copy link
Closed
Labels
Description
Summary of a problem or a feature request
Get error Internal error: Undefined class constant 'KIND_SEMICOLON' when running phpstan
------ --------------------------------------------------------------
Line app/MyService/Thing/Manager.php
------ --------------------------------------------------------------
Internal error: Undefined class constant 'KIND_SEMICOLON'
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new
------ --------------------------------------------------------------
mbp:myapp petah$ phpstan analyse -l 4 -c phpstan.neon laravel/app/ --debug
/Users/petah/work/myapp/laravel/app/MyService/Thing/Manager.php
PHP Fatal error: Uncaught Error: Undefined class constant 'KIND_SEMICOLON' in phar:///Users/petah/work/commands/phpstan/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php:255
Stack trace:
#0 phar:///Users/petah/work/commands/phpstan/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php(236): PhpParser\Parser\Php7->PhpParser\Parser\{closure}(4)
#1 phar:///Users/petah/work/commands/phpstan/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php(140): PhpParser\ParserAbstract->doParse()
#2 phar:///Users/petah/work/commands/phpstan/src/Parser/DirectParser.php(36): PhpParser\ParserAbstract->parse('<?php namespace...')
#3 phar:///Users/petah/work/commands/phpstan/src/Parser/DirectParser.php(28): PHPStan\Parser\DirectParser->parseString('<?php namespace...')
#4 phar:///Users/petah/work/commands/phpstan/src/Parser/CachedParser.php(25): PHPStan\Parser\DirectParser->parseFile('/Users/petah...')
#5 phar:///Users/petah/work/commands/phpstan/src/Analyser/Analyser.php(91): PHPStan\ in phar:///Users/petah/work/commands/phpstan/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 255
Code snippet that reproduces the problem
(I couldn't create a small script to reproduce the problem), but the file causing it looked like:
namespace MyApp\MyService\Thing;
use Illuminate\Foundation\Bus\DispatchesJobs;
use MyApp\Models\MyModel;
class Manager extends \MyApp\Manager implements \MyApp\MyInterface
{
use \MyApp\MyTrait;
use DispatchesJobs;
protected $apiKey;
public $identifierSlug = 'testmachine';
public $serviceType = MyModel::SERVICE_TYPE;
public $targetDirectory = 'path\to\file';
public $pollingInterval = 600;
public function serviceName()
{
return 'TestService';
}
public function applicableTaxes($customerTerritoryId)
{
return $this->getApplicableTaxesByName('Test Tax', 'US');
}
public function enforceVendorRules($order)
{
return true;
}
}
PHPStan - PHP Static Analysis Tool 0.10.3
PHP 7.1.19 (cli) (built: Jun 25 2018 10:42:21) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.19, Copyright (c) 1999-2018, by Zend Technologies
Reactions are currently unavailable
Activity
ondrejmirtes commentedon Aug 30, 2018
ondrejmirtes commentedon Sep 5, 2018
Hi, I can't reproduce this. Can you create a minimal repo with this example? I had to reduce the example to this and it works like it should:
Petah commentedon Sep 9, 2018
Sorry I couldn't create a small reproducible example. I'll close for now and re-open if I manage to.
Petah commentedon Feb 13, 2019
@ondrejmirtes I figured out why this is happening.
My project requires
nikic/php-parser v2.1.1, and phpstan is autoloading the version from my project instead of the version phpstan requires. I'm not really sure if anything can be done about this though.Petah commentedon Feb 13, 2019
I managed to work around this by forcing an updated version of php-parser by putting this in my projects composer.json file:
"nikic/php-parser": "v4.2.0 as v2.1.1"Seems to work for me at least because the the old version of nikic/php-parser was a dependency of a dependency that wasn't really used.
ondrejmirtes commentedon May 23, 2020
This should no longer be happening. Please try PHPStan 0.12.25.
lock commentedon Jun 24, 2020
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
BTW: Did you know that PHPStan now has a brand new website with a user guide, guide to writing analyser-friendly PHP code, and a guide to developing PHPStan extensions? Visit phpstan.org today!