Skip to content

Language: typed class constants — array/string fold + type check (#3592) - #3600

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-3592-typed-class-constants
May 30, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-3592-typed-class-constants

Conversation

@PurHur

@PurHur PurHur commented May 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • PHP 8.3 typed class constants (const array X = [1,2];, const string S = 'a';) now compile and run on the VM: literal arrays are folded at compile time, stored in the class constant table, and support dim-fetch (C::X[0]).
  • Declared type mismatches fail at compile time with TypeError (e.g. const string S = 1).
  • php-cfg patch preserves declaredType on class const nodes; JIT lowering stores immutable array constants via HashTableHelper::variableFromVmHashTable (LLVM class-const fetch remains fragile in harness — pre-existing JIT segfault on class const fetch).

php-src reference

  • Zend/zend_compile.c — zend_compile_class_const
  • Zend/zend_constants.c — constant table + type info
  • Zend/zend_type.c — zend_verify_const_type

Test plan

  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "class C { public const array X = [1, 2]; } echo C::X[0];"' → 1
  • ./vendor/bin/phpunit test/compliance/VMTest.php --filter typed_class_const
  • JIT: ./vendor/bin/phpunit test/compliance/JITTest.php --filter typed_class_const (segfault on class const fetch in current harness — same as existing class_member_const JIT cases)

Closes #3592

Made with Cursor

Materialize literal typed class constants at compile time (including array
literals), validate declared types, and store values on VM defineClass.
Adds php-cfg patch for declaredType on class const nodes and compliance
tests for array dim-fetch and compile-time type mismatch.

php-src: Zend/zend_compile.c (zend_compile_class_const),
Zend/zend_constants.c, Zend/zend_type.c (zend_verify_const_type)

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur force-pushed the agent/issue-3592-typed-class-constants branch from 455f7c7 to 46480a5 Compare May 30, 2026 10:51
@PurHur
PurHur merged commit 7eeeded into master May 30, 2026
@PurHur
PurHur deleted the agent/issue-3592-typed-class-constants branch May 30, 2026 10:51
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.

Language: typed class constants — const array/string/int (PHP 8.3, Zend zend_constants.c parity)

1 participant