Repository navigation
Language: Class constant fetch on user-defined classes (Router::CONST) #2215
Copy link
Copy link
Closed
Labels
area:compilerCompiler / CFG / JITCompiler / CFG / JITarea:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestphase-2:languagePhase 2 – language featuresPhase 2 – language features
Description
Problem
examples/003-MiniWebApp uses Router::DEFAULT_CONTACT_NAME_MAX inside global function miniwebapp_contact_name_is_valid() (see examples/003-MiniWebApp/src/Router.php). Related trackers:
- Language: class member constants (private/public const in class bodies) #2199 — declaring member constants (
public constin class body) - Language: static methods on user-defined classes (Expr_StaticCall) #2209 — static methods (
Expr_StaticCall)
Fetching a constant on a user class (Expr_ClassConstFetch) is a separate acceptance path: lint may pass declaration while fetch still fails VM/JIT/AOT, blocking honest #2059 curls.
Goal
VM + JIT + AOT resolve ClassName::CONST for user-defined classes (integer literals minimum for MiniWebApp).
./phpc lint examples/003-MiniWebApp/src/Router.php
./phpc run -q 'name='$(python3 -c 'print("x"*201)') examples/003-MiniWebApp/example.php
# invalid long name rejected; valid short name acceptedImplementation hints
| Layer | Files | Notes |
|---|---|---|
| Compiler | lib/Compiler.php compileClassConstFetch |
Already emits TYPE_CLASS_CONST_FETCH; verify user-class operands |
| VM | lib/VM.php class tables |
Store member consts at class init; resolve fetch opcode |
| JIT | lib/JIT.php / lib/JIT/Builtin/Type/Object_.php |
defineClassConst / fetch lowering for internal + user classes |
| AOT | native class metadata | Same as VM const table |
| Tests | test/compliance/cases/classes/class_const_fetch_user.phpt |
Router-style class + global helper |
Search before coding
rg 'TYPE_CLASS_CONST_FETCH|compileClassConstFetch' lib/
rg 'defineClassConst' lib/VM.php lib/JIT/Acceptance criteria
./script/ci-fast.sh --filter ClassConstFetch
./phpc lint --all examples/003-MiniWebApp # no unsupported on Router::CONST fetchHarness (Runforge — do not use raw docker run -v):
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter ClassConstFetch'Dependencies
- Language: class member constants (private/public const in class bodies) #2199 — member const declaration
- Language: Class methods and property access in JIT #58, Language: Visibility, constructors, and destructors #145 — class methods / visibility
- Testing: MiniWebApp VM OOP e2e — phpc serve Router when #58/#145/#54 land #2059 — MiniWebApp VM OOP e2e umbrella
Links
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:compilerCompiler / CFG / JITCompiler / CFG / JITarea:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestphase-2:languagePhase 2 – language featuresPhase 2 – language features
Activity
Hoist user class declarations before FUNCDEF for const fetch (#2215)
Language: hoist user classes before FUNCDEF for const fetch (#2215)
Hoist user class declarations before FUNCDEF for const fetch (#2215)
Language: hoist user classes before FUNCDEF for const fetch (#2215)
Merge pull request #2226 from PurHur/issue-2215-class-const-fetch-user