Skip to content

Internal error: Undefined class constant 'KIND_SEMICOLON' #1386

Closed

Description

@Petah

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

Activity

  1. ondrejmirtes commented on Aug 30, 2018

    @ondrejmirtes
    Member
  2. ondrejmirtes commented on Sep 5, 2018

    @ondrejmirtes
    Member

    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:

    <?php
    
    namespace MyApp\MyService\Thing;
    
    use Illuminate\Foundation\Bus\DispatchesJobs;
    use MyApp\Models\MyModel;
    
    class Manager
    {
    
    	const SERVICE_TYPE = 'aaa';
    
        protected $apiKey;
    
        public $identifierSlug = 'testmachine';
        public $serviceType = self::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;
        }
    
    }
  3. Petah commented on Sep 9, 2018

    @Petah
    Author

    Sorry I couldn't create a small reproducible example. I'll close for now and re-open if I manage to.

  4. Petah commented on Feb 13, 2019

    @Petah
    Author

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

  5. reopened this on Feb 13, 2019
  6. Petah commented on Feb 13, 2019

    @Petah
    Author

    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.

  7. ondrejmirtes commented on May 23, 2020

    @ondrejmirtes
    Member

    This should no longer be happening. Please try PHPStan 0.12.25.

  8. lock commented on Jun 24, 2020

    @lock

    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!

  9. locked as resolved and limited conversation to collaborators on Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions