Skip to content

Skip pipe/array_map optimization for forbid-dynamic-calls functions - #25672

Open
prateekbhujel wants to merge 2 commits into
php:PHP-8.6from
prateekbhujel:fix/forbid-dynamic-calls-partial-apply
Open

prateekbhujel wants to merge 2 commits into
php:PHP-8.6from
prateekbhujel:fix/forbid-dynamic-calls-partial-apply

Conversation

@prateekbhujel

@prateekbhujel prateekbhujel commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #25546 for the extract() / compact() / func_get_arg() case in GH-25379.

When zend_partial_apply() optimizes an FCC/PFA in array_map() or |>, rewriting it into a direct call skips the dynamic call check so functions flagged with ZEND_ACC2_FORBID_DYN_CALLS end up running directly in the caller's scope instead of throwing Error: Cannot call ...() dynamically.

This checks ZEND_ACC2_FORBID_DYN_CALLS in zend_is_pipe_optimizable_callable_name() (covering resolved function names, aliases, and namespace fallback to global functions). Resolving the function name there also avoids hitting the assert() assertion failure when assert is imported under an alias like use function assert as a;.

/cc @arnaud-lb

When zend_partial_apply() rewrites an FCC/PFA in array_map() or |> into a
direct call, functions and static methods flagged with
ZEND_ACC2_FORBID_DYN_CALLS bypass zend_forbid_dynamic_call() and run in the
caller's scope (e.g. extract(), compact(), func_get_arg()).

Resolve the callable name in zend_is_pipe_optimizable_callable() and skip
the optimization if it targets a ZEND_ACC2_FORBID_DYN_CALLS function or
static method (including namespace fallback and aliases). Resolving the
name also fixes aliased assert() hitting an assertion failure in
zend_ast_export_ex().
Comment thread Zend/zend_compile.c Outdated
return !fbc || !(fbc->common.fn_flags2 & ZEND_ACC2_FORBID_DYN_CALLS);
}

static bool zend_is_pipe_optimizable_method_name(

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.

We can ignore method calls for now: We do not have any methods like that except in ext/zend_test and we can not implement this check reliably as we don't generally know the CE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, dropped the method call check and the zend_test test in 0a9510d, just checking function names now.

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.

2 participants