Skip to content

Deleting an entity with hooked identifier property on PHP 8.4 throws an error #12077

@CiBeRHeMuL

Description

@CiBeRHeMuL

Bug Report

Q A
Version 3.5.0

Summary

Deleting an entity with hooked identifier property on PHP 8.4 throws an error "Cannot unset hooked property EntityClass::$id"

Current behavior

After deleting entity from database Doctrine trying to unset identifier property on entity object, but if identifier property has hook PHP throws an error, because unsetting property with hook does not supported

Expected behavior

Doctrine delete an entity with hooked identifier property successfully

How to reproduce

  1. Create an entity with hooked identifier property
<?php

use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity]
#[ORM\Table('entity')]
class Entity
{
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(UuidGenerator::class)]
    #[ORM\Column(type: 'uuid', nullable: false)]
    public Uuid $id {
        get => $this->id;
        set => $this->id = $value;
    }
}

Create and delete entity

<?php

$entity = new Entity();

$em->persist($entity);
$em->flush();

$em->remove($entity);
$em->flush(); // An exception is thrown here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions