Skip to content

[Feature]: type PHP member-call receivers from return types, docblocks, properties and callers #5696

Backlog

Description

@livingforelvis

Problem or use case

Repro (4 files, no config):

// Factory.php
class Factory {
    /** @return Actions */
    public function get_actions_instance() { return new Actions(); }
    public function make_validator() { return new Validator($this); }
}
// Validator.php
class Validator {
    private $_factory;
    public function __construct($factory) { $this->_factory = $factory; }
    public function check() {
        $actions = $this->_factory->get_actions_instance();
        return $actions->is_game_over();
    }
}
// Actions.php:      class Actions      { public function is_game_over() { return false; } }
// OtherActions.php: class OtherActions { public function is_game_over() { return true; } }

calls edges from Validator::check() via extract():

Graphify edges
v8 d249de3 (0.9.124) none
expected .get_actions_instance() -> Factory.php, .is_game_over() -> Actions.php; never OtherActions.php

Proposed solution

  • Type a receiver from what produced it, step by step, all INFERRED (0.85):
    • a function's return type (native or @return); an undeclared return from its returns
    • a local's nearest earlier assignment; an if/else that assigns related classes in its arms keeps each class
    • @param / @var docblocks
    • an untyped property from what its class stores in it
    • an untyped constructor or method parameter from what its new sites and callers pass; several classes meet at their nearest common base
  • A call typed to a base class also reaches the subclass overrides a factory hands out (a class some non-test function returns), not every subclass
  • A step that names no one class binds nothing; a chain with an unknown step falls back to today's file table, so no existing edge is lost

Alternatives considered

  • Treat every named new X() passed to an untyped parameter as a possible value of it: tried on a large legacy codebase, 9 of 25 sampled new edges reached an unrelated sibling class; dropped for the per-arm rule above
  • Bind an untyped ->m() by method name alone: not done; it guesses where no type evidence exists

Area

Extraction (PHP)

Are you willing to submit a PR?

Yes, PR ready.

Activity

  1. github-actions commented on Dec 1, 2026

    @github-actions

    Thanks for opening this issue, @livingforelvis. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions