orm icon indicating copy to clipboard operation
orm copied to clipboard

🐛 Using static call in entity classes will result in TypeError

Open rauanmayemir opened this issue 2 years ago • 0 comments

No duplicates 🥲.

  • [X] I have searched for a similar issue in our bug tracker and didn't find any solutions.

What happened?

Using constructs like new static will result in TypeError when the entities are proxied.

This is expected behaviour, but in reality people could accidentally forget it. So if we have an entity like:

class Post
{
    public ?string $title = null;
    public ?string $body = null;

    public function duplicate(string $newTitle): static
    {
        $self = new static();
        $self->title = $newTitle;
        $self->body = $this->body;

        return $self;
    }
}

If this post is loaded as part of a parent's relation, it's going to be a cycle proxy object, not an actual class. in that case calling $parent->post->duplicate('Some new title') would effectively crash.

Version

ORM 2.0.0
PHP 8.0

rauanmayemir avatar Feb 23 '22 11:02 rauanmayemir