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

self cannot be used in trait params #1475

Closed
muglug opened this issue Mar 16, 2019 · 2 comments
Closed

self cannot be used in trait params #1475

muglug opened this issue Mar 16, 2019 · 2 comments
Labels

Comments

@muglug
Copy link
Collaborator

muglug commented Mar 16, 2019

Erroneous UndefinedClass with the following:

<?php

trait CompareTrait
{
    public static function min(self $object, self ...$objects): self
    {
        foreach ($objects as $other) {
            if ($other->compareTo($object) < 0) {
                $object = $other;
            }
        }

        return $object;
    }

    public static function max(self $object, self ...$objects): self
    {
        foreach ($objects as $other) {
            if ($other->compareTo($object) > 0) {
                $object = $other;
            }
        }

        return $object;
    }

    abstract public function compareTo(self $other): int;

    public function equals(self $other): bool
    {
        return 0 === $this->compareTo($other);
    }
}

class Foo
{
    use CompareTrait;
  
    public function compareTo(self $other): int
    {
        return 0;
    }
}
@gharlan
Copy link
Contributor

gharlan commented Mar 17, 2019

@muglug Thanks for the really quick fix!

There seems to be still an issue, when I move the compareTo method to trait: https://psalm.dev/r/74606ca7c9

@gharlan
Copy link
Contributor

gharlan commented Mar 17, 2019

Another similar case: https://psalm.dev/r/ff2f2509b8

@muglug muglug reopened this Mar 17, 2019
@muglug muglug closed this as completed in 2f8bfff Mar 17, 2019
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