Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions 7 src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,9 @@ private function getPropertiesConsideringAlreadyVisitedClasses(AlreadyVisitedCla
foreach ($trait->getPropertiesConsideringAlreadyVisitedClasses($alreadyVisitedClasses) as $traitProperty) {
$traitPropertyName = $traitProperty->getName();

if (
array_key_exists($traitPropertyName, $properties)
|| array_key_exists($traitPropertyName, $immediateProperties)
) {
$existingProperty = $immediateProperties[$traitPropertyName] ?? $properties[$traitPropertyName] ?? null;

if ($existingProperty !== null && ! $existingProperty->isAbstract()) {
continue;
}

Expand Down
42 changes: 42 additions & 0 deletions 42 test/unit/Reflection/ReflectionClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3169,4 +3169,46 @@ protected function hello(int $i): void
self::assertTrue($hello->isProtected());
self::assertCount(1, $hello->getParameters());
}

public function testInterfacePropertyImplementedInTrait(): void
{
$php = <<<'PHP'
<?php

interface TimestampsInterface
{
public \DateTimeImmutable $createdAt { get; }
}

trait Timestamps
{
public private(set) \DateTimeImmutable $createdAt {
get {
return $this->createdAt ??= new \DateTimeImmutable();
}
}
}

class Example implements TimestampsInterface
{
use Timestamps;
}
PHP;

$classInfo = (new DefaultReflector(new StringSourceLocator($php, $this->astLocator)))->reflectClass('Example');

self::assertTrue($classInfo->hasProperty('createdAt'));

/** @var trait-string $traitClassName */
$traitClassName = 'Timestamps';
/** @var class-string $className */
$className = 'Example';

$propertyInfo = $classInfo->getProperty('createdAt');
self::assertSame($traitClassName, $propertyInfo->getDeclaringClass()->getName());
self::assertSame($className, $propertyInfo->getImplementingClass()->getName());
self::assertFalse($propertyInfo->isVirtual());
self::assertTrue($propertyInfo->isPublic());
self::assertTrue($propertyInfo->isPrivateSet());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.