Skip to content

Fix partial application treating methods named assert() as the global assert() - #25771

Merged
arnaud-lb merged 3 commits into
php:PHP-8.6from
hohphu8:fix-pfa-method-named-assert
Nov 26, 2026
Merged

arnaud-lb merged 3 commits into
php:PHP-8.6from
hohphu8:fix-pfa-method-named-assert

Conversation

@hohphu8

@hohphu8 hohphu8 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

In zp_compile_forwarding_call() (Zend/zend_partial.c), is_assert is decided by comparing only the function name with "assert". A partial application of a method named assert, such as $obj->assert(?) or Cls::assert(?), therefore matches, and the generated code calls \call_user_func('assert', ...), which invokes the global assert() instead of the method. With zend.assertions=1 this throws an AssertionError instead of calling the method.

This restricts the check to internal functions without a class scope (function->type == ZEND_INTERNAL_FUNCTION && !function->common.scope).

Adds Zend/tests/partial_application/method_named_assert.phpt covering instance and static methods named assert, plus a control that partial application of the real \assert(?) still works. It fails before the fix and passes after.

Note: I found this through source inspection with an automated/LLM-assisted tool, then reproduced and verified it myself.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 04:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@DanielEScherzer DanielEScherzer 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.

this should probably be targeting PHP 8.6 rather than master

zp_compile_forwarding_call() checked function_name against ZEND_STR_ASSERT without checking ZEND_INTERNAL_FUNCTION and
      common.scope == NULL, causing partial application on methods or user functions named assert() to call global assert().
@hohphu8
hohphu8 force-pushed the fix-pfa-method-named-assert branch from 4b28892 to e621cc5 Compare November 26, 2026 05:09
@hohphu8
hohphu8 changed the base branch from master to PHP-8.6 November 26, 2026 05:11
@hohphu8

hohphu8 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

thanks, moved to PHP-8.6. same code is there and the test passes on it

@TimWolla
TimWolla requested a review from arnaud-lb November 26, 2026 08:08

@TimWolla TimWolla 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.

Seems correct.

* PHP-8.6:
  Fix stale string metadata in sodium_add() and sodium_increment() (php#25775)
  Sync `session.upload_progress.enabled` default in `php.ini-{development,production}` (php#25743)
  ext/pgsql: fix pg_fetch_object() JIT crash when constructor keeps $this
  Fix hash() and hash_file() hanging on invalid xxh3/xxh128 options (php#25777)
  Fix phar_set_inode() using the zend_string header instead of the filename (php#25768)
  Fix phpGH-25360: ZipArchive assertion when error handler throws at shutdown (php#25361)
@arnaud-lb
arnaud-lb merged commit 415e68c into php:PHP-8.6 Nov 26, 2026
1 check passed
arnaud-lb added a commit that referenced this pull request Nov 26, 2026
* PHP-8.6:
  Fix partial application treating methods named assert() as the global assert() (#25771)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

@hohphu8
hohphu8 deleted the fix-pfa-method-named-assert branch November 26, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants