Skip to content

Stdlib: implement class_constants() — interface/enum constant maps (#7309)#7326

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-class-constants-7309
Jun 7, 2026
Merged

Stdlib: implement class_constants() — interface/enum constant maps (#7309)#7326
PurHur merged 1 commit into
masterfrom
agent/stdlib-class-constants-7309

Conversation

@PurHur
Copy link
Copy Markdown
Owner

@PurHur PurHur commented Jun 7, 2026

Summary

  • Implements class_constants(string $class): array in ext/standard/class_constants_.php with VM helpers in VmReflection::fetchClassEntryForClassConstants() / classConstantsArray().
  • Registers the builtin in ext/standard/Module.php; JIT/AOT lowering in ext/standard/JitClassConstants.php via compile-time class constant tables (Object_::classConstFetch()), returning enum case objects not backing scalars (php-src-strict, Zend/zend_constants.c).
  • php-src reference: ext/standard/basic_functions.cPHP_FUNCTION(class_constants); behavior aligned with ReflectionClass::getConstants() on PHP 8.2 reference.

Closes #7309

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit test/unit/ClassConstantsBuiltinTest.php
vendor/bin/phpunit --filter class_constants test/compliance/VMTest.php
vendor/bin/phpunit --filter class_constants test/compliance/JITTest.php
php bin/vm.php -r "interface I { const X = 1; } enum E: string { case A = \"a\"; } var_export(class_constants(\"I\")); echo \"\n\"; var_export(class_constants(E::class));"
sed -n "/^--FILE--$/,/^--EXPECT--$/p" test/fixtures/aot/cases/class_constants.phpt | sed "1d;\$d" > /tmp/class_constants_aot.php
php bin/compile.php -l /tmp/class_constants_aot.php
'

Results (2026-06-07 harness):

  • ClassConstantsBuiltinTest: OK (3 tests)
  • VMTest --filter class_constants: OK (3 tests)
  • JITTest --filter class_constants: OK (3 tests)
  • Issue repro VM: array('X'=>1) + enum case map with \E::A objects
  • bin/compile.php -l on AOT fixture body: exit 0

AOT link note: bin/compile.php -o currently segfaults (exit 139) for all AOT fixtures on this harness host, including pre-existing class_parents_get_class_vars — not introduced by this PR. AOT fixture + -l gate added for when link is restored.

PHP-in-PHP

No new C runtime symbols; behavior lives in ext/standard/ + lib/JIT/Builtin/Type/Object_.php display-name helper only.

Made with Cursor

Add VM handler backed by class metadata, JIT/AOT lowering via compile-time
class constant tables, and compliance tests matching php-src enum case objects.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

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

1 participant