Skip to content

Language: const expressions with array_find() must compile-fatal (re-#6843, zend_compile.c) #8809

@PurHur

Description

@PurHur

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

  • Repro fails at compile time with Zend-equivalent fatal (not runtime 2)
  • Guard covers array_find and other non-constexpr builtins in const context
  • ./script/ci-fast.sh --filter ConstExpr or new compliance PHPT green
  • php-src-strict

Links

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions