diff --git a/lib/VM.php b/lib/VM.php index b0471f16948..6b5802ab330 100755 --- a/lib/VM.php +++ b/lib/VM.php @@ -1422,6 +1422,10 @@ private function runFrames(): int } $propertyObject = $var->toObject(); VM\LazyObjectSupport::ensureInitialized($this, $propertyObject); + if (EnumCaseSupport::isEnumCase($propertyObject)) { + $result->copyFrom(EnumCaseSupport::getProperty($propertyObject, $name)); + break; + } $hookValue = $this->fetchPropertyWithHooks($propertyObject, $name, $frame); if (null !== $hookValue) { $result->copyFrom($hookValue); @@ -2375,7 +2379,7 @@ private function isPropertyHookRawWrite(Frame $frame, string $propName): bool $methodLc = strtolower($func->name); $wantSet = strtolower(SourcePreprocessor\PropertyHooks::setHookMethodName($propName)); - return $methodLc === $wantSet || $methodLc === strtolower($func->class.'::'.$wantSet); + return $methodLc === $wantSet || $methodLc === strtolower($func->class->value.'::'.$wantSet); } private function linkPropertyHooks(ClassEntry $entry, VM\ClassProperty $prop): void diff --git a/lib/VM/EnumCaseSupport.php b/lib/VM/EnumCaseSupport.php index 391d2d3966e..b9fa70b0d1b 100644 --- a/lib/VM/EnumCaseSupport.php +++ b/lib/VM/EnumCaseSupport.php @@ -37,12 +37,13 @@ public static function getProperty(ObjectEntry $object, string $name): Variable throw new \LogicException('getProperty called on non-enum-case object'); } $result = new Variable(); - if ('name' === $name) { + $lc = strtolower($name); + if ('name' === $lc) { $result->string($object->enumCaseName ?? ''); return $result; } - if ('value' === $name) { + if ('value' === $lc) { if (null === $object->enumCaseValue) { throw new \LogicException('Cannot read value on a unit enum case'); } diff --git a/test/compliance/EnumVMTest.php b/test/compliance/EnumVMTest.php index e495db5cc8b..46c1879d436 100644 --- a/test/compliance/EnumVMTest.php +++ b/test/compliance/EnumVMTest.php @@ -21,6 +21,8 @@ public static function providePHPTests(): \Generator 'enum_instanceof.phpt', 'enum_implements_metadata.phpt', 'enum_static_method.phpt', + 'enum_user_method.phpt', + 'enum_backed_user_method.phpt', ] as $file ) { yield $file => self::parsePHPT( diff --git a/test/compliance/cases/language/enum_backed_user_method.phpt b/test/compliance/cases/language/enum_backed_user_method.phpt new file mode 100644 index 00000000000..eddbf43a998 --- /dev/null +++ b/test/compliance/cases/language/enum_backed_user_method.phpt @@ -0,0 +1,16 @@ +--TEST-- +Language: backed enum instance method (#3390) +--FILE-- +name; + } +} +echo Status::Active->label(); +echo "\n"; +echo Status::Active; +--EXPECT-- +Active +active diff --git a/test/compliance/cases/language/enum_user_method.phpt b/test/compliance/cases/language/enum_user_method.phpt new file mode 100644 index 00000000000..ecb5aae3e09 --- /dev/null +++ b/test/compliance/cases/language/enum_user_method.phpt @@ -0,0 +1,17 @@ +--TEST-- +Language: unit enum instance method and $this->name (#3390) +--FILE-- +name; + } +} +echo Status::Ok->label(); +echo "\n"; +echo Status::Err->label(); +--EXPECT-- +Ok +Err