Skip to content

[PFA 3/n] Support PFA in const exprs#22785

Draft
arnaud-lb wants to merge 8 commits into
php:masterfrom
arnaud-lb:partials-const-expr-simple
Draft

[PFA 3/n] Support PFA in const exprs#22785
arnaud-lb wants to merge 8 commits into
php:masterfrom
arnaud-lb:partials-const-expr-simple

Conversation

@arnaud-lb

Copy link
Copy Markdown
Member

See individual commits. First two are GH-22783 and GH-22784, which will be merged separately.

Preloading will try to evaluate class constants during compilation, but
evaluated FCCs are objects, which can not be persisted. Apply the same fix as
for enums: Fail evaluation when compiling.

Preloading will also reset CG(map_ptr_last) after compilation, which results in
collisions if map ptrs were allocated during compilation. Move the
ZEND_MAP_PTR_NEW() to the persist phase, as a shared map ptr is not necessary
before that.
… of the declaring opline itself

This makes the API compatible with creating partials from AST:
We can pass &ast->lineno to zend_partial_create()
@arnaud-lb arnaud-lb changed the title [PFA 3/n] Support PFA in const exprs [wip][PFA 3/n] Support PFA in const exprs Jul 17, 2026
The declaring op_array is used for multiple purposes:
 * Generating a PFA name
 * Finding the filename
 * Finding whether op_array is cached, and therefore whether the PFA should be
   cached too

However it's not available when evaluating a PFA AST.

Remove the declaring_op_array argument, and pass the relevant information
directly:
 * Generate the filename at compile time, pass it as argument to zend_partial_create()
 * Pass the filename and a cacheable flag as argument to zend_partial_create()
@arnaud-lb arnaud-lb changed the title [wip][PFA 3/n] Support PFA in const exprs [PFA 3/n] Support PFA in const exprs Jul 17, 2026

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

I reviewed the PR excluding the first two commits. The tests LGTM. For the implementation, I didn't see obvious issues (except formatting nits), but I'm not fully comfortable approving the C changes.

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 is the same as Zend/tests/partial_application/constexpr_008.phpt

Comment thread Zend/zend_compile.c
zend_error_noreturn(E_COMPILE_ERROR, "Variadic placeholder must be last");
}
} else {

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 empty line should not be here.

Comment thread Zend/zend_ast.c
0, func, 0, NULL);

for (uint32_t i = 0; i < args_ast->children; i++) {

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.

Empty line at start of block.

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