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

Add return type extension for constant() #2474

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Jun 20, 2023

Had that idea when phpstan/phpstan#9295 was created.

See https://www.php.net/manual/en/function.constant.php and https://3v4l.org/66no7

UPDATE: prior to PHP 8 it would trigger a warning for inexistent constants and return null. But not sure if it's worth the effort to implement this. right now it would just return *ERROR* for such cases. UPDATE2: this feels related to also support non-existing constants as expressions, so I'll refrain from adding any code for it for now. E.g. https://3v4l.org/FTHPv / https://phpstan.org/r/c649b7bb-8031-4210-9c4b-c469eba63d3b

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@herndlm herndlm changed the base branch from 1.11.x to 1.10.x June 20, 2023 21:29
@herndlm herndlm force-pushed the constant branch 4 times, most recently from a99340f to ba461b2 Compare June 21, 2023 08:17
assertType('mixed', constant($constantName));
}

assertType("'foo'", FOO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the asserts be moved into a function or method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but not sure if they really hurt here :)

@ondrejmirtes ondrejmirtes merged commit be378e1 into phpstan:1.10.x Jun 22, 2023
382 of 388 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm herndlm deleted the constant branch June 22, 2023 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants