doctrine / doctrine/annotations

PHP 8 Annotations bug?

Open
#388 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
6.7k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

Hello!

My stack:
php: 8.0.0
symfony: 5.2
doctrine/orm: 2.8.1
doctrine/doctrine-bundle: 2.2.2

I have the next entitity:
![entity](https://d.radikal.ru/d24/2012/42/2f22392ea15f.jpg)

I try to request a user by his login through the repository
```php
return new Response(
$this->userRepository->findOneBy(['login' => 'someLogin'])->getLogin()
);
```

and catch the next error:
![error](https://c.radikal.ru/c29/2012/8c/d0496699eafc.jpg)

This is due to the fact that the Doctrine annotation parser tries to go through all the properties of the annotation @ORM\Id (see the first screenshot).
And since they don't exist, the foreach loop passes null and I catch this error.

To confirm my words, I attach screenshots from the xdebug:

Doctrine\Common\Annotations\CachedReader::getPropertyAnnotation()
![xdeb1](https://b.radikal.ru/b38/2012/d6/d47ba8ec1410.jpg)

Doctrine\Common\Annotations\CachedReader::getPropertyAnnotations()
![xdeb2](https://a.radikal.ru/a03/2012/40/ed0970ca5811.jpg)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.