Question: type-safe proxies #6686

Closed
opened 2026-01-22 15:37:02 +01:00 by admin · 2 comments
Owner

Originally created by @signor-pedro on GitHub (Apr 8, 2021).

Hi, I am using psalm heavily and have reached a situation where I can have

public function doSth(EntityInterface|Proxy $entity): bool
{
    //....
}

All my entities implement the EntityInterface, because I enforce that every entity has a getId() method.

Obviously, my psalm now cries

Method Doctrine\Common\Proxy\Proxy::getId does not exist

Is there some adviced way to make Proxies type-safe? Thank you

Originally created by @signor-pedro on GitHub (Apr 8, 2021). Hi, I am using psalm heavily and have reached a situation where I can have ``` public function doSth(EntityInterface|Proxy $entity): bool { //.... } ``` All my entities implement the EntityInterface, because I enforce that every entity has a `getId()` method. Obviously, my psalm now cries ``` Method Doctrine\Common\Proxy\Proxy::getId does not exist ``` Is there some adviced way to make Proxies type-safe? Thank you
admin closed this issue 2026-01-22 15:37:02 +01:00
Author
Owner

@beberlei commented on GitHub (Apr 8, 2021):

Why do you typehint for proxy? You should not need this.

Correct typehint is EntityInterface|(EntityInterface&Proxy)

@beberlei commented on GitHub (Apr 8, 2021): Why do you typehint for proxy? You should not need this. Correct typehint is EntityInterface|(EntityInterface&Proxy)
Author
Owner

@signor-pedro commented on GitHub (Apr 8, 2021):

Thank you very much- I did not know of the intersection types.

@signor-pedro commented on GitHub (Apr 8, 2021): Thank you very much- I did not know of the intersection types.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6686