Skip to content

Stdlib: class_constants() — class/interface/enum constant map missing (ext/standard/basic_functions.c) #7309

@PurHur

Description

@PurHur

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions