Category
bug · php-src-strict · language / inheritance
Problem
Zend forbids narrowing class constant visibility on inheritance (public const → private const in a child). php-compiler accepts the composition (prints compiled, exit 0). Accessing B::X later fails at runtime (Cannot access private constant) instead of the Zend compile fatal.
| Repro |
Zend 8.2+ (2026-07-24) |
VM (2026-07-24) |
class A { public const X = 1; } class B extends A { private const X = 2; } echo "compiled\n"; |
Fatal: Access level to B::X must be public (as in class A) (exit 255) |
compiled (exit 0) |
php-src reference
PHP implementation target
lib/ inheritance / class-const composition check — when overriding an inherited class const, require visibility ≥ parent (same Zend message)
- Prefer PHP compile-time guard; no new
runtime/*.c
Repro
./script/docker-exec.sh -- bash -lc 'cat >/tmp/const_vis.php <<'"'"'PHP'"'"'
<?php
class A { public const X = 1; }
class B extends A { private const X = 2; }
echo "compiled\n";
PHP
php /tmp/const_vis.php; echo zend:$?
php bin/vm.php /tmp/const_vis.php; echo vm:$?'
Done when
Category
bug· php-src-strict · language / inheritanceProblem
Zend forbids narrowing class constant visibility on inheritance (
public const→private constin a child). php-compiler accepts the composition (printscompiled, exit 0). AccessingB::Xlater fails at runtime (Cannot access private constant) instead of the Zend compile fatal.class A { public const X = 1; } class B extends A { private const X = 2; } echo "compiled\n";Access level to B::X must be public (as in class A)(exit 255)compiled(exit 0)php-src reference
Zend/zend_inheritance.c— class constant compatibility / access levelZend/zend_compile.c— const declarationPHP implementation target
lib/inheritance / class-const composition check — when overriding an inherited class const, require visibility ≥ parent (same Zend message)runtime/*.cRepro
Done when
Access level to B::X must be public (as in class A).phptundertest/compliance/cases/language/