Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug : Uncaught RuntimeException: PHP Error: Undefined offset: 0 on clean code #8141

Closed
mazerti opened this issue Jun 22, 2022 · 4 comments
Closed
Assignees

Comments

@mazerti
Copy link

mazerti commented Jun 22, 2022

I found this which looks like a bug on windows : when I run vendor\bin\psalm --init on a blank project with only psalm installed (latest version) an the following code I get an Error :

Code :

<?php
/**
 * Allow the setup page to load and perform its checks (including the check about the required extensions)
 */
if (!class_exists('DOMDocument'))
{
	/**
	 * Class DOMDocument
	 */
	class DOMDocument {
		function __construct(){throw new Exception('The dom extension is not enabled');}
	}
}


/**
 * Allow the setup page to load and perform its checks (including the check about the required extensions)
 */
if (!class_exists('DOMElement'))
{
	/**
	 * Class DOMElement
	 */
	class DOMElement {
		function __construct(){throw new Exception('The dom extension is not enabled');}
	}
}

Error :

C:\Users\mazerti\Documents\static_analysis\Psalm\test>vendor\bin\psalm --init
Calculating best config level based on project files
Target PHP version: 7.4 (inferred from current PHP version)
Scanning files...
Analyzing files...

Uncaught RuntimeException: PHP Error: Undefined offset: 0 in C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FunctionLikeAnalyzer.php:1274 in C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\ErrorHandler.php:66
Stack trace:
#0 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FunctionLikeAnalyzer.php(1274): Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}(8, 'Undefined offse...', 'C:\\Users\\Titoua...', 1274, Array)
#1 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FunctionLikeAnalyzer.php(358): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->processParams(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Storage\MethodStorage), 'DOMElement::__c...', Array, Array, Object(Psalm\Context), false)
#2 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(1787): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), NULL)
#3 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(424): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\ClassAnalyzer), Object(Psalm\Context), NULL)
#4 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(591): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), NULL)
#5 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(206): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Class_), Object(Psalm\Context), NULL)
#6 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfElse\IfAnalyzer.php(68): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#7 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfElseAnalyzer.php(365): Psalm\Internal\Analyzer\Statements\Block\IfElse\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Internal\Scope\IfConditionalScope), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Context), Array)
#8 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(517): Psalm\Internal\Analyzer\Statements\Block\IfElseAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#9 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(206): Psalm\Internal\Analyzer\StatementsAnalyzer::analyzeStatement(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context), NULL)
#10 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FileAnalyzer.php(205): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), NULL, true)
#11 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(362): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#12 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(619): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(0, 'C:\\Users\\Titoua...')
#13 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(291): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#14 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ProjectAnalyzer.php(685): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1, false, true)
#15 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\src\Psalm\Internal\Cli\Psalm.php(373): Psalm\Internal\Analyzer\ProjectAnalyzer->check('C:\\Users\\Titoua...', true)
#16 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\vimeo\psalm\psalm(6): Psalm\Internal\Cli\Psalm::run(Array)
#17 C:\Users\mazerti\Documents\static_analysis\Psalm\test\vendor\bin\psalm(112): include('C:\\Users\\Titoua...')
#18 {main}
(Psalm 4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88 crashed due to an uncaught Throwable)

Note : The same appear when I run psalm after having manually added a config file. Surprisingly enough, I get no Issue on the website : https://psalm.dev/r/c7e6b8bdcd

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/c7e6b8bdcd
<?php
/**
 * Allow the setup page to load and perform its checks (including the check about the required extensions)
 */
if (!class_exists('DOMDocument'))
{
	/**
	 * Class DOMDocument
	 */
	class DOMDocument {
		function __construct(){throw new Exception('The dom extension is not enabled');}
	}
}


/**
 * Allow the setup page to load and perform its checks (including the check about the required extensions)
 */
if (!class_exists('DOMElement'))
{
	/**
	 * Class DOMElement
	 */
	class DOMElement {
		function __construct(){throw new Exception('The dom extension is not enabled');}
	}
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/AttributesAnalyzer.php: Psalm\Internal\Analyzer\AttributesAnalyzer::analyze(): Argument #4 ($attribute_groups) must be of type array, null given, called in /vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1281

@orklah
Copy link
Collaborator

orklah commented Jun 22, 2022

Psalm.dev returns

Warning: Undefined array key 0 in /var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1278

Warning: Attempt to read property "attrGroups" on null in /var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php on line 1278
{"error":{"message":"\/vendor\/vimeo\/psalm\/src\/Psalm\/Internal\/Analyzer\/AttributesAnalyzer.php: Psalm\\Internal\\Analyzer\\AttributesAnalyzer::analyze(): Argument #4 ($attribute_groups) must be of type array, null given, called in \/vendor\/vimeo\/psalm\/src\/Psalm\/Internal\/Analyzer\/FunctionLikeAnalyzer.php on line 1281","line_from":63,"type":"psalm_error"}}

so it reproduce it too :)

@orklah
Copy link
Collaborator

orklah commented Jun 22, 2022

@AndrolGenhald looks like an attribute analysis issue, mind looking at it?

@AndrolGenhald AndrolGenhald self-assigned this Jun 24, 2022
@orklah orklah closed this as completed in e751a27 Jun 26, 2022
orklah added a commit that referenced this issue Jun 26, 2022
Fix crash when redefining method with fewer params (fixes #8141).
@mazerti
Copy link
Author

mazerti commented Jun 27, 2022

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants