phan / phan/phan

Make `__invoke()` shorthand work with static return types

Open
#1,719 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.