Skip to content

Fix "Unsafe use of new static when trait enforces constructor via abstract method" #4114

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

Merged
merged 2 commits into from
Jul 21, 2025

Conversation

VincentLanglet
Copy link
Contributor

Closes phpstan/phpstan#9654

Closes #2767

@VincentLanglet VincentLanglet marked this pull request as ready for review July 18, 2025 23:54
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

if ($traitReflection->hasConstructor()) {
$traitConstructor = $traitReflection->getConstructor();

if ($traitConstructor instanceof PhpMethodReflection && $traitConstructor->isAbstract()) {
Copy link
Member

Choose a reason for hiding this comment

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

Why it has to be instanceof PhpMethodReflection? Such code is usually very brittle.

@ondrejmirtes ondrejmirtes merged commit 0082df6 into phpstan:2.1.x Jul 21, 2025
411 of 419 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

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

Successfully merging this pull request may close these issues.

Unsafe use of new static when trait enforces constructor via abstract method
3 participants