Skip to content

PHP 8.4 property hooks: get/set bodies dropped, refs missing #1445

Description

@Widthdom

Summary

PHP 8.4 introduces property hooks: public string $foo { get => $this->_foo; set => $this->_foo = $value; }. The current PHP extractor does not recognize the { get => … set => … } clause attached to a property declaration, so the hook bodies are dropped entirely. Any references inside them (calls into other methods, type uses) are missed.

Evidence

  • src/CodeIndex/Indexer/Extraction/LanguageReferenceExtraction.Php.cs — the property-declaration parser terminates at ; and does not enter { … } when present on a property.

  • Reproducer:

    class User {
      public string $displayName {
        get => $this->firstName . ' ' . $this->lastName;
        set => $this->_displayName = strtoupper($value);
      }
    }

    Index this file; references to firstName, lastName, strtoupper will all be missing.

Impact

  • PHP 8.4 codebases (becoming common during 2025-2026) will have systematic reference gaps for any code expressed via property hooks.
  • references on common helpers (strtoupper, validation funcs) under-reports their callers.

Proposed direction

  • Extend the property-declaration parser to optionally consume a { get => …; set => …; } block.
  • Index the hook as a child member of the property (similar shape to the Swift observer fix proposed in the sibling Swift issue).
  • Walk the hook expression as code so its references emit normally.

Repro env

  • Branch: main @ 2ee912d (release v1.21.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions