[PR #24] Add reflection typed no default property class #33

Closed
opened 2026-01-24 11:24:53 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/reflection/pull/24

State: closed
Merged: Yes


Implementation for issue https://github.com/doctrine/reflection/issues/23
See discussion in https://github.com/doctrine/orm/pull/7857

As suggested by @beberlei, the \Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty class was introduced.
It will be returned in doctrine/persistence package class RuntimeReflectionService::getAccessibleProperty if the property is typed and has no default value. Something like this:

/**
 * {@inheritDoc}
 */
public function getAccessibleProperty(string $class, string $property) : ?ReflectionProperty
{
    $reflectionProperty = new ReflectionProperty($class, $property);

    if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) {
        $reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property);
    } elseif ($reflectionProperty->isPublic()) {
        $reflectionProperty = new RuntimePublicReflectionProperty($class, $property);
    }

    $reflectionProperty->setAccessible(true);

    return $reflectionProperty;
}

Also updated phpunit config as suggested in the discussion in the same issue https://github.com/doctrine/reflection/issues/23.
This allows skipping tests containing php 7.4 specific syntax on builds with lesser php versions.
Also updated travis-ci.yml Lint job to ignore such tests by phpstan analysis, if the php version is less than 7.4

**Original Pull Request:** https://github.com/doctrine/reflection/pull/24 **State:** closed **Merged:** Yes --- Implementation for issue https://github.com/doctrine/reflection/issues/23 See discussion in https://github.com/doctrine/orm/pull/7857 As suggested by @beberlei, the `\Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty` class was introduced. It will be returned in `doctrine/persistence` package class [RuntimeReflectionService::getAccessibleProperty](https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Mapping/RuntimeReflectionService.php) if the property is typed and has no default value. Something like this: ```php /** * {@inheritDoc} */ public function getAccessibleProperty(string $class, string $property) : ?ReflectionProperty { $reflectionProperty = new ReflectionProperty($class, $property); if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) { $reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property); } elseif ($reflectionProperty->isPublic()) { $reflectionProperty = new RuntimePublicReflectionProperty($class, $property); } $reflectionProperty->setAccessible(true); return $reflectionProperty; } ``` Also updated phpunit config as suggested in the discussion in the same issue https://github.com/doctrine/reflection/issues/23. This allows skipping tests containing php 7.4 specific syntax on builds with lesser php versions. Also updated `travis-ci.yml` Lint job to ignore such tests by phpstan analysis, if the php version is less than 7.4
admin added the pull-request label 2026-01-24 11:24:53 +01:00
admin closed this issue 2026-01-24 11:24:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/reflection#33