Skip to content

Fix fatal error on dynamic method names in assignments - #143

Merged
iMattPro merged 6 commits into
masterfrom
copilot/fix-undefined-method-error
Nov 2, 2026
Merged

iMattPro merged 6 commits into
masterfrom
copilot/fix-undefined-method-error

Conversation

Copilot AI commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

EPV crashed with Call to undefined method PhpParser\Node\Expr\ArrayDimFetch::toString() when scanning an assignment whose right-hand side is a method call with an array-indexed dynamic name, e.g. $removed = $this->store->{$methods[$step]}(self::DELETE_STEP);.

Root cause

  • In validateMethodCalls, the assignment branch ($node->expr is a MethodCall) skipped only a fixed list of name node types: Variable, PropertyFetch, Concat, Encapsed and Ternary.
  • Every other type fell through to $node->expr->name->toString(). ArrayDimFetch was one of them, and it has no toString().

Change

  • Replaced the denylist with an allowlist in src/Tests/Tests/epv_test_validate_php_functions.php. toString() is now called only when the name is a Node\Identifier or Node\Name, which are the only types that have it.
  • Any other dynamic name is skipped, as the old skip list already did. This also covers other expression types the denylist missed.
// before
&& !($node->expr->name instanceof Variable || ... || $node->expr->name instanceof Ternary)
// after
&& ($node->expr->name instanceof Node\Identifier
    || $node->expr->name instanceof Node\Name)

Not run: the checkout had no vendor directory, so only php -l was run. I didn't add a regression test or try the zip from the issue. It's worth checking $x = $obj->{$arr[$i]}() against the real extension.

Copilot AI linked an issue Nov 1, 2026 that may be closed by this pull request
Co-authored-by: iMattPro <303711+iMattPro@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix fatal error caused by undefined method in Reactions extension Fix fatal error on dynamic method names in assignments Nov 1, 2026
Copilot AI requested a review from iMattPro November 1, 2026 18:10

@iMattPro iMattPro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for this change

Copilot AI and others added 2 commits November 1, 2026 18:59
Co-authored-by: iMattPro <303711+iMattPro@users.noreply.github.com>
Co-authored-by: iMattPro <303711+iMattPro@users.noreply.github.com>

Copilot AI commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Add tests for this change

Added test_usage_dynamic_method_name_in_assignment with fixture tests/testFiles/dynamic_method_call.php. It covers $x = $this->store->{$methods[$step]}(...). The test errors with the original ArrayDimFetch::toString() crash without the fix and passes with it. All 13 tests in that file pass.

Co-authored-by: iMattPro <303711+iMattPro@users.noreply.github.com>
Copilot AI requested a review from iMattPro November 1, 2026 18:59

@iMattPro iMattPro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are all these lint files you added to the bin dir? That's not what I asked for. And why are phpunit results caches added to gitignore - also something we've not needed before. Get rid of this noise!

Co-authored-by: iMattPro <303711+iMattPro@users.noreply.github.com>
Copilot AI requested a review from iMattPro November 1, 2026 19:04
@iMattPro
iMattPro marked this pull request as ready for review November 1, 2026 19:13
@iMattPro
iMattPro merged commit 0e340da into master Nov 2, 2026
8 checks passed
@iMattPro
iMattPro deleted the copilot/fix-undefined-method-error branch November 2, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fatal error, Call to undefined method

2 participants