Incorrect type handling of 'self' in 'traits'
Danil42Russia opened this issue · 1 comments
Danil42Russia commented
<?php
trait TrainA {
private ?string $name = null;
public function name(string $name): self {
$this->name = $name;
return $this;
}
}
class ClassA {
use TrainA;
private ?string $description = null;
public function description(string $description): self {
$this->description = $description;
return $this;
}
public function __toString(): string {
return "name: " . $this->name . PHP_EOL .
"description: " . $this->description . PHP_EOL;
}
}
function main() {
$a = (new ClassA())
->name("name")
->description("description");
echo $a;
}
main();
Actual Behavior:
<critical> ERROR undefinedMethod: Call to undefined method {\TrainA}->description() at index.php:33
->description("description");
^^^^^^^^^^^
Expected Behavior:
No error
YuriyNasretdinov commented
Yeah when I initially added support for Traits, it was just to prevent reporting false positives for trait usage, but in general traits were not analysed properly and not really supported. I wonder if that changed since.