Problem
Web apps use const VERSION = '1.0';, define('DEBUG', true);, and class constants for config. The compiler lowers classes and globals but user-defined constants are incomplete:
examples/003-MiniWebApp/config.php is a plain return [...] array today; constants become important once config moves to define() / class constants.
Goal
const APP_NAME = 'MiniWeb';
define('MAX_UPLOAD', 1024);
class Config { public const ENV = 'prod'; }
echo APP_NAME, Config::ENV;
VM + JIT + AOT: immutable fetches; define() registers before use in same request.
Implementation hints
Compiler (lib/Compiler.php)
| Construct |
Lowering |
Stmt\Const_ |
Add to compilation unit constant table at compile time |
define() |
Builtin or opcode TYPE_DEFINE with name + value |
Class const |
Extend compileClassBody — store in class metadata, TYPE_CLASS_CONST_FETCH |
VM (lib/VM.php)
- Global constant table keyed by name (case-sensitive)
- Class constant table on class entry
define() checks defined() / duplicate semantics (Zend subset)
JIT / AOT
- Inline literal constants where opcode is
TYPE_CONST_FETCH with known value
- JIT: emit global as LLVM global or immediate
Lint
- Register unsupported const forms in
UnsupportedRegistry until implemented
Tests
test/compliance/cases/const_global.phpt
test/compliance/cases/define_runtime.phpt
test/compliance/cases/class_const.phpt
script/capability-matrix.php if builtins added
Acceptance criteria
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
php bin/vm.php -r 'const X=42; define("Y",1); echo X+Y;'
Prints 43. JIT parity when #98 LLVM group runs.
Verification (local / Docker only)
./script/ci-local.sh --filter const_
No GitHub Actions.
Dependencies
Links
Problem
Web apps use
const VERSION = '1.0';,define('DEBUG', true);, and class constants for config. The compiler lowers classes and globals but user-defined constants are incomplete:const NAME = …may not reach the VM constant tabledefine('NAME', value)runtime registration is missing or partialconstinsidecompileClassBodyis not handled alongside properties (Language: Class methods and property access in JIT #58 / Language: Visibility, constructors, and destructors #145)examples/003-MiniWebApp/config.phpis a plainreturn [...]array today; constants become important once config moves todefine()/ class constants.Goal
VM + JIT + AOT: immutable fetches;
define()registers before use in same request.Implementation hints
Compiler (
lib/Compiler.php)Stmt\Const_define()TYPE_DEFINEwith name + valueconstcompileClassBody— store in class metadata,TYPE_CLASS_CONST_FETCHVM (
lib/VM.php)define()checksdefined()/ duplicate semantics (Zend subset)JIT / AOT
TYPE_CONST_FETCHwith known valueLint
UnsupportedRegistryuntil implementedTests
test/compliance/cases/const_global.phpttest/compliance/cases/define_runtime.phpttest/compliance/cases/class_const.phptscript/capability-matrix.phpif builtins addedAcceptance criteria
Prints
43. JIT parity when #98 LLVM group runs.Verification (local / Docker only)
No GitHub Actions.
Dependencies
__DIR__if config uses path constantsLinks
lib/Compiler.php,lib/VM.php,lib/OpCode.php