Category
stdlib
Problem
PHP exposes class_constants(string $class): array returning an associative map of class/interface/enum constants (names → values). This compiler has constant("Class::NAME"), ReflectionClassConstant, and enum cases(), but class_constants() is not registered — calls fail with Call to undefined function class_constants().
php-src reference
Repro (failure today)
<?php
interface I { const X = 1; }
enum E: string { case A = 'a'; case B = 'b'; }
var_export(class_constants('I'));
var_export(class_constants(E::class));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_dump(function_exists(\"class_constants\"));"
php repro.php
php repro.php # Zend reference
'
Observed (VM): function_exists('class_constants') → false; repro fatal.
Expected (Zend): array('X' => 1) and enum case name → case object map.
Implementation hints (PHP-in-PHP)
- Handler in
ext/standard/class_constants.php backed by existing compiler class/enum metadata (mirror constant() resolution in ext/standard/constant.php).
- Register in
ext/standard/Module.php; VM via reflection/class tables in lib/VM.php / lib/Compiler/.
- JIT/AOT: lower from compile-time class tables where possible; otherwise VM builtin.
- Compliance:
test/compliance/cases/stdlib/class_constants*.phpt (class, interface, enum, not-found TypeError).
php-src-strict
- Invalid class name →
Error/TypeError matching Zend.
- Enum returns case objects, not backing scalars.
Pairs
Category
stdlibProblem
PHP exposes
class_constants(string $class): arrayreturning an associative map of class/interface/enum constants (names → values). This compiler hasconstant("Class::NAME"),ReflectionClassConstant, and enumcases(), butclass_constants()is not registered — calls fail withCall to undefined function class_constants().php-src reference
ext/standard/basic_functions.c—PHP_FUNCTION(class_constants)Zend/zend_constants.c— class constant table iterationRepro (failure today)
Observed (VM):
function_exists('class_constants')→false; repro fatal.Expected (Zend):
array('X' => 1)and enum case name → case object map.Implementation hints (PHP-in-PHP)
ext/standard/class_constants.phpbacked by existing compiler class/enum metadata (mirrorconstant()resolution inext/standard/constant.php).ext/standard/Module.php; VM via reflection/class tables inlib/VM.php/lib/Compiler/.test/compliance/cases/stdlib/class_constants*.phpt(class, interface, enum, not-found TypeError).php-src-strict
Error/TypeErrormatching Zend.Pairs
ReflectionClass::getConstants()registration)ReflectionClassConstantparity)