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

Incorrect type handling of 'self' in 'traits' #1201

Open
Danil42Russia opened this issue Oct 11, 2022 · 1 comment
Open

Incorrect type handling of 'self' in 'traits' #1201

Danil42Russia opened this issue Oct 11, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@Danil42Russia
Copy link
Contributor

<?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
@Danil42Russia Danil42Russia added the bug Something isn't working label Oct 11, 2022
@YuriyNasretdinov
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants