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

Crashing on arguments with default value self::class #4713

Closed
e1himself opened this issue Mar 17, 2021 · 4 comments
Closed

Crashing on arguments with default value self::class #4713

e1himself opened this issue Mar 17, 2021 · 4 comments

Comments

@e1himself
Copy link

e1himself commented Mar 17, 2021

Bug report

PHPStan crashes when trying to parse code with arguments having default value set to self::class.

<?php

class Service
{
	public static function createInstance(string $class = self::class): Service
	{
		return new $class();
	}
}

$service = Service::createInstance();

Internal error: Failed to find parent class of constant "class". Run PHPStan with --debug option and post the stack trace to: https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

This seems to be related to #4288, but not exactly.

Stack trace:

PHP Fatal error:  Uncaught LogicException: Failed to find parent class of constant "class". in phar:///source/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionParameter.php:192
Stack trace:
#0 phar:///source/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionParameter.php(146): PHPStan\BetterReflection\Reflection\ReflectionParameter->findParentClassDeclaringConstant('class')
#1 phar:///source/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionParameter.php(257): PHPStan\BetterReflection\Reflection\ReflectionParameter->parseDefaultValueNode()
#2 phar:///source/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionParameter.php(274): PHPStan\BetterReflection\Reflection\ReflectionParameter->getDefaultValue()
#3 phar:///source/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionParameter.php(322): in phar:///source/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionParameter.php on line 192

Code snippet that reproduces the problem

https://phpstan.org/r/1c85152d-6693-4420-9811-9301934276ac

Expected output

No errors.

@ondrejmirtes
Copy link
Member

Alternative that works right now: https://phpstan.org/r/df453653-bc3e-4934-a648-995d4946eac3

@ondrejmirtes
Copy link
Member

Fixed: ondrejmirtes/BetterReflection@a41da9f + phpstan/phpstan-src@431905c

@e1himself
Copy link
Author

Awesome! Thanks @ondrejmirtes 🙇

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants