Skip to content

Language: class member constants (private/public const in class bodies) #2199

Closed

Description

@PurHur

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 ClassMemberConst

Implementation 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

Acceptance criteria

./phpc run -r 'class C { private const X = 1; } echo C::X;'
# or compliance PHPT green

./script/ci-fast.sh --filter ClassMemberConst

Harness:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter ClassMemberConst'

No GitHub Actions (#394 ✅).

Dependencies

Links

Activity

  1. added a commit that references this issue on May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions