Category
language · php-src-strict
Problem
PHP 8.4 allows asymmetric visibility on promoted constructor parameters:
class C {
public function __construct(public private(set) int $x = 1) {}
}
$c = new C(2);
echo $c->x; // Zend: 2
This compiler fails at parse/compile (Syntax error, unexpected T_ECHO / parser chokes on public private(set) in promotion position). Non-promoted asymmetric properties (public private(set) int $x) may parse elsewhere — this issue is promotion + asymmetric visibility only.
php-src reference
Repro (failure today)
<?php
class C {
public function __construct(public private(set) int $x = 1) {}
}
echo (new C(2))->x, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_asym_promoted.php # PHP 8.4+: 2
php bin/vm.php repro_asym_promoted.php
'
| Engine |
Result |
| Zend PHP 8.4+ |
compiles; prints 2; external $c->x = 3 → Error (private set) |
| VM today |
parse/compile failure |
Scope (PHP-in-PHP first)
| Path |
Work |
lib/SourcePreprocessor/ or php-parser grammar hooks |
accept asymmetric modifiers on promoted params |
lib/Compiler.php |
emit promoted property with asymmetric ACC flags |
lib/VM.php |
enforce get/set visibility masks on promoted props |
| Tests |
test/compliance/cases/language/asymmetric_promoted_ctor.phpt |
Reflection: #5060 / #6772 once properties compile.
Done when (php-src-strict)
Related
Category
language· php-src-strictProblem
PHP 8.4 allows asymmetric visibility on promoted constructor parameters:
This compiler fails at parse/compile (
Syntax error, unexpected T_ECHO/ parser chokes onpublic private(set)in promotion position). Non-promoted asymmetric properties (public private(set) int $x) may parse elsewhere — this issue is promotion + asymmetric visibility only.php-src reference
Zend/zend_language_parser.y— promoted parameter modifiersZend/zend_compile.c—ZEND_ACC_ASYMMETRIC_*on promoted propertiesZend/zend_property_hooks.c— interaction with hooks (orthogonal)Repro (failure today)
2; external$c->x = 3→ Error (private set)Scope (PHP-in-PHP first)
lib/SourcePreprocessor/or php-parser grammar hookslib/Compiler.phplib/VM.phptest/compliance/cases/language/asymmetric_promoted_ctor.phptReflection: #5060 / #6772 once properties compile.
Done when (php-src-strict)
2$c->xworks; write from outside throws Zend-shapedError./script/ci-fast.sh --filter asymmetric_promoted_ctorgreenRelated