DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
84 stars 10 forks source link

Incorrectly getting incompatible types when overriding traits PHP2439 #657

Closed zeConehead closed 2 months ago

zeConehead commented 2 months ago

When a class is using a trait, but is overriding a method from the trait, the extending class still expects the type of the trait and not the overridden function.

Code to reproduce:

<?php

trait T {
    public function foo(string $s): string {
        return $s;
    }
}

class A {
    use T;

    public function foo(int $i): int {
        return $i;
    }
}

class B extends A {

    public function foo(int $i): int {
        return $i;
    }
}

Declaration of B::foo(int $i): int must be compatible with A::foo(string $s): stringPHP(PHP2439)

jakubmisek commented 2 months ago

Thank you for the test case!

Fixed. Will be included in the next update.