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

Using "new static" should not trigger UnsafeInstantiation in final classes #4019

Closed
AegirLeet opened this issue Aug 18, 2020 · 3 comments
Closed
Labels

Comments

@AegirLeet
Copy link

https://psalm.dev/r/722b67a5a0

As there can't be any child classes, the constructor's signature is known in this case. UnsafeInstantiation shouldn't apply.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/722b67a5a0
<?php

final class FooException extends RuntimeException
{
    public static function make(): self
    {
        return new static('foo');
    }
}
Psalm output (using commit 7ac6d2e):

ERROR: UnsafeInstantiation - 7:16 - Cannot safely instantiate class FooException with "new static" as its constructor might change in child classes

@muglug muglug added the bug label Aug 18, 2020
@muglug
Copy link
Collaborator

muglug commented Aug 18, 2020

You can also fix this with new self

@AegirLeet
Copy link
Author

Yeah I just prefer static everywhere for consistency.

@muglug muglug closed this as completed in ebe3739 Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants