Skip to content

Cannot call an abstract static method #3007

Closed
@vudaltsov

Description

@vudaltsov
Contributor

Since 3.10 this code breaks. https://psalm.dev/r/94b8f284f0
It's certainly right that an abstract static method cannot be called from the abstract class itself, but how can I tell psalm that I have an array of implementing class names?

Activity

psalm-github-bot

psalm-github-bot commented on Mar 23, 2020

@psalm-github-bot

I found these snippets:

https://psalm.dev/r/94b8f284f0
<?php

abstract class A
{
    abstract public static function name(): string;
}

final class B extends A
{
    public static function name(): string
    {
        return 'b';
    }
}

final class C extends A
{
    public static function name(): string
    {
        return 'c';
    }
}

/** @var list<class-string<A>> $classes */
$classes = [B::class, C::class];

foreach ($classes as $class) {
    echo $class::name();
}
Psalm output (using commit 2043e85):

ERROR: AbstractMethodCall - 28:10 - Cannot call an abstract static method A::name directly
muglug

muglug commented on Mar 23, 2020

@muglug
Collaborator

Thanks, this is fixed in 3.10.1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @muglug@vudaltsov

        Issue actions

          Cannot call an abstract static method · Issue #3007 · vimeo/psalm