Skip to content

Fix crash when a partial skips a param with a constant default#184

Open
iliaal wants to merge 1 commit into
masterfrom
fix/pfa-const-default-gap-crash
Open

Fix crash when a partial skips a param with a constant default#184
iliaal wants to merge 1 commit into
masterfrom
fix/pfa-const-default-gap-crash

Conversation

@iliaal

@iliaal iliaal commented Jul 18, 2026

Copy link
Copy Markdown
Owner

A partial that leaves an optional parameter unbound via a named-argument gap, where that parameter's default is a constant expression, crashes the compiler. f(a: 10, c: ?) for function f($a, $b = SOME_CONST, $c = 0) compiled the callee default into the generated forwarding call as a ZEND_AST_CONSTANT node, which zend_compile_expr_inner has no case for: ZEND_ASSERT(0) in debug, __builtin_unreachable UB in release. A plain literal default ($b = 5) is unaffected.

For a user function, this skips the unbound parameter in the forwarding call and passes the following arguments by name, so the target applies its own default at call time. That matches a normal call exactly (verified for global constants, self:: class constants, and enum cases) and materializes no value, so it is safe under opcache for defaults that cannot be stored as a literal, such as enum cases. Internal functions are unchanged: they still pass an explicit default and error when it is not introspectable.

When a partial leaves an optional parameter unbound (a positional gap from
named arguments) and its default is a constant expression, the default AST
was compiled into the forwarding call as an uncompilable ZEND_AST_CONSTANT
node: an assertion in debug builds, undefined behavior otherwise. For a
user function, skip the parameter and pass the following arguments by name
so the target applies its own default at call time; this materializes no
value and handles every default kind, including enum cases that cannot be
a literal. Internal functions still pass an explicit default and error if
it is not introspectable.
@iliaal
iliaal force-pushed the fix/pfa-const-default-gap-crash branch from 28dbd3c to c2117da Compare July 19, 2026 00:37
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.

1 participant