Make `__invoke()` shorthand work with static return types
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- PHP
- Stars
- 5.6k
- Forks
- 365
- Avg merge
- 1h 25m
- Merged PRs (30d)
- 6
Description
<?php
class C {
/**
* @return static
* (or (at)return $this)
*/
public function g() {
return $this;
}
/**
* @return static
*/
public function __invoke(...$args) {
var_export($args);
return $this;
}
}
class D extends C {
public function methodOfD() {
}
}
class E extends D {
public function methodOfE() {
}
}
$e = new E();
echo $e->g()->methodOfD();
echo $e->g()->methodOfE();
echo $e->g()->undeclaredMethod(); // warns
echo $e()->methodOfD();
echo $e()->methodOfE();
echo $e()->undeclaredMethod(); // should warn, but doesn't yet
echo $e->__invoke()->undeclaredMethod(); // warns
EDIT(2019-01-06): This incorrectly emits PhanContextNotObject Cannot access static when not in object context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in this issue and trace how Phan handles the __invoke() shorthand and @return static annotations. Add or update a regression test so calls through $e() report undeclared methods like direct __invoke() calls, without emitting the incorrect PhanContextNotObject warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100