Repository navigation
Language: class member constants (private/public const in class bodies) #2199
Description
Problem
examples/003-MiniWebApp/src/Router.php declares private const DEFAULT_CONTACT_NAME_MAX = 200; (line 28). #58 / #145 track methods and visibility; #2185 tracks ::class / static factory — but class member constant declaration (Stmt_ClassConst in class body) has no dedicated language tracker.
Fetching constants (Router::DEFAULT_CONTACT_NAME_MAX in global code) is #2215 — separate acceptance path. This issue covers declaration + in-class use; close #2215 after fetch works.
Lint may still report unsupported Stmt_ClassConst even when instance OOP lands, blocking honest phpc lint --all examples/003-MiniWebApp for #2059.
Goal
VM + JIT + AOT compile user classes with public / private / protected member constants (integer literals minimum for MiniWebApp).
./phpc lint examples/003-MiniWebApp/src/Router.php
# no unsupported Stmt_ClassConst on Router
vendor/bin/phpunit --filter ClassMemberConstImplementation hints
| Layer | Files | Notes |
|---|---|---|
| Compiler | lib/Compiler.php compileClassBody() |
Lower Stmt_ClassConst into class metadata table |
| VM | lib/VM.php, class init |
Store const values at class registration |
| JIT | lib/JIT.php |
Inline const reads in method bodies where possible |
| AOT | lib/AOT/ |
Const slots in TU metadata (#1803 graph) |
| Lint | lib/Lint/UnsupportedRegistry.php |
Allow 003 patterns |
| Tests | test/compliance/cases/language/class_member_const.phpt |
VM; test/fixtures/aot/ when ready |
Unblock order
#58 / #145 (class shape) → this issue (declare) → #2215 (fetch in global fn) → #2059 VM serve
MiniWebApp touchpoints
examples/003-MiniWebApp/src/Router.php—private const DEFAULT_CONTACT_NAME_MAXexamples/003-MiniWebApp/public/index.php— uses const via Language: Class constant fetch on user-defined classes (Router::CONST) #2215 inminiwebapp_contact_name_is_valid()
Acceptance criteria
./phpc run -r 'class C { private const X = 1; } echo C::X;'
# or compliance PHPT green
./script/ci-fast.sh --filter ClassMemberConstHarness:
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter ClassMemberConst'No GitHub Actions (#394 ✅).
Dependencies
- Language: Class methods and property access in JIT #58, Language: Visibility, constructors, and destructors #145 — class body compiles
- Language: Class constant fetch on user-defined classes (Router::CONST) #2215 —
Expr_ClassConstFetch(downstream consumer) - Testing: MiniWebApp VM OOP e2e — phpc serve Router when #58/#145/#54 land #2059 — VM OOP e2e acceptance
- Docs: capabilities-matrix OOP rows (class methods, visibility, constructors) #2190 — capabilities-matrix OOP rows
Links
- Language: static methods on user-defined classes (Expr_StaticCall) #2209 static methods (orthogonal)
- ROADMAP 🗺️ ROADMAP: Self-host + web-capable PHP subset (living) #78 Phase 1 Language
Activity
Merge pull request #2212 from PurHur/agent/class-member-const-2199