diff --git a/src/Resolver/ClassConstantValueTrait.php b/src/Resolver/ClassConstantValueTrait.php index 70eb88fd..ce5b2252 100644 --- a/src/Resolver/ClassConstantValueTrait.php +++ b/src/Resolver/ClassConstantValueTrait.php @@ -69,6 +69,19 @@ trait ClassConstantValueTrait : $value; } } + if ($this->hasInterface($class)) { + $constant = $this->findCompileTimeInterfaceConstant($class, $name); + if ($constant !== null) { + [$interface, $constantDef] = $constant; + return $this->evaluateCompileTimeClassConstant( + $expr, + $interface, + $constantDef, + $name, + $interface, + ); + } + } [$inheritedFound, $inherited] = $this->resolveInheritedClassConst($class, $name); if ($inheritedFound) { return $inherited; diff --git a/tests/compiler/const/interface-const-property-default.phpt b/tests/compiler/const/interface-const-property-default.phpt new file mode 100644 index 00000000..ea5a0670 --- /dev/null +++ b/tests/compiler/const/interface-const-property-default.phpt @@ -0,0 +1,70 @@ +--TEST-- +Interface constants can initialize properties composed from a trait +--FILE-- + OutputInterface::VERBOSITY_VERBOSE, + 'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE, + 'vvv' => OutputInterface::VERBOSITY_DEBUG, + 'quiet' => OutputInterface::VERBOSITY_QUIET, + 'normal' => OutputInterface::VERBOSITY_NORMAL, + ]; + + public function getVerbosity(): int + { + return $this->verbosity; + } + + public function getVerbosityMap(): array + { + return $this->verbosityMap; + } + } + + class Command + { + use InteractsWithIO; + } +} + +namespace { + function main(): void + { + $command = new Issue112\Command(); + var_dump($command->getVerbosity()); + var_dump($command->getVerbosityMap()); + } +} +?> +--EXPECT-- +int(32) +array(5) { + ["v"]=> + int(64) + ["vv"]=> + int(128) + ["vvv"]=> + int(256) + ["quiet"]=> + int(16) + ["normal"]=> + int(32) +}