Category
language — compile-time validation
Problem
Class/const constant expressions that call non-constexpr builtins must be a compile-time fatal in Zend. Closed #6843 added this guard, but const C = array_find([...], fn(...) => ...) still compiles and evaluates at runtime in this compiler.
php-src reference
Repro
test/repro/maintainer_const_array_find.php:
<?php
const C = array_find([1, 2, 3], fn($v) => $v > 1);
var_export(C);
echo "\n";
php test/repro/maintainer_const_array_find.php
# Zend: Fatal error: Constant expression contains invalid operations
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_const_array_find.php'
# VM today: 2
|
Zend |
VM today |
const C = array_find(...) |
compile fatal |
compiles; prints 2 |
Scope
lib/Compiler.php (or php-cfg) constant-expression validator — reject function calls / closures in const initializers unless Zend-constexpr
- VM must not evaluate illegal const expressions at runtime
- Shared with enum/class const and
define() constexpr paths where applicable
Done when
Links
Category
language— compile-time validationProblem
Class/const constant expressions that call non-constexpr builtins must be a compile-time fatal in Zend. Closed #6843 added this guard, but
const C = array_find([...], fn(...) => ...)still compiles and evaluates at runtime in this compiler.php-src reference
Zend/zend_compile.c—zend_compile_const_expr/ invalid operations in constant expressionsext/standard/array.c—array_find()(not constexpr)Repro
test/repro/maintainer_const_array_find.php:const C = array_find(...)2Scope
lib/Compiler.php(or php-cfg) constant-expression validator — reject function calls / closures inconstinitializers unless Zend-constexprdefine()constexpr paths where applicableDone when
2)array_findand other non-constexpr builtins in const context./script/ci-fast.sh --filter ConstExpror new compliance PHPT greenLinks
array_find$strict parameter — separate runtime parity)