Category
Language: · php-src-strict · class constant evaluation
Problem
Mutual / self-referencing class constants must throw Error: Cannot declare self-referencing constant self::Y (Zend detects the cycle while declaring/evaluating). VM instead surfaces Error: Undefined constant A::X when the cycle is first read.
Probed 2026-08-17 — host Zend PHP 8.2 vs php bin/vm.php.
| Repro |
Zend 8.2+ |
VM (2026-08-17) |
class A { public const X = self::Y; public const Y = self::X; } then echo A::X |
Error: Cannot declare self-referencing constant self::Y |
Error: Undefined constant A::X |
class A {
public const X = self::Y;
public const Y = self::X;
}
try {
echo A::X;
} catch (Throwable $e) {
echo $e->getMessage(), "\n";
}
php-src reference
PHP implementation target
lib/ class-constant evaluation / resolution — detect cycles and throw Zend’s self-referencing Error (do not report a one-sided “Undefined constant” when the peer name exists but is mid-evaluation)
- php-in-PHP — no new C runtime branch
Repro
./script/docker-exec.sh -- bash -lc 'php test/repro/maintainer_gap_self_referencing_class_const.php'
./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_self_referencing_class_const.php'
Done when
Category
Language:· php-src-strict · class constant evaluationProblem
Mutual / self-referencing class constants must throw
Error: Cannot declare self-referencing constant self::Y(Zend detects the cycle while declaring/evaluating). VM instead surfacesError: Undefined constant A::Xwhen the cycle is first read.Probed 2026-08-17 — host Zend PHP 8.2 vs
php bin/vm.php.class A { public const X = self::Y; public const Y = self::X; }thenecho A::XError: Cannot declare self-referencing constant self::YError: Undefined constant A::Xphp-src reference
Zend/zend_constants.c— self-referencing constant detection /Cannot declare self-referencing constantZend/zend_compile.c— class const AST evaluation / cycle markingPHP implementation target
lib/class-constant evaluation / resolution — detect cycles and throw Zend’s self-referencing Error (do not report a one-sided “Undefined constant” when the peer name exists but is mid-evaluation)Repro
Done when
Cannot declare self-referencing constant …Error (message + that it is thrown on access/declare consistently with Zend)self::OTHERclass consts still resolve.phptguard undertest/compliance/cases/