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

Open
opened 2026-01-22 15:53:07 +01:00 by admin · 3 comments
Owner

Originally created by @CiBeRHeMuL on GitHub (Jul 17, 2025).

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
Originally created by @CiBeRHeMuL on GitHub (Jul 17, 2025). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | 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 <?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 <?php $entity = new Entity(); $em->persist($entity); $em->flush(); $em->remove($entity); $em->flush(); // An exception is thrown here ```
admin added the Bug label 2026-01-22 15:53:07 +01:00
Author
Owner

@BusterNeece commented on GitHub (Jul 18, 2025):

Can confirm the same issue is present when hydrating lazy collections with hooked properties whose values are null. The property accessor is trying to unset them, which it no longer can do with hooked properties:

e714b1a2fc/src/Mapping/PropertyAccessors/TypedNoDefaultPropertyAccessor.php (L43-L45)

@BusterNeece commented on GitHub (Jul 18, 2025): Can confirm the same issue is present when hydrating lazy collections with hooked properties whose values are `null`. The property accessor is trying to unset them, which it no longer can do with hooked properties: https://github.com/doctrine/orm/blob/e714b1a2fca7a95e0a71347a46e55a6127977f7a/src/Mapping/PropertyAccessors/TypedNoDefaultPropertyAccessor.php#L43-L45
Author
Owner

@abramchikd commented on GitHub (Aug 17, 2025):

I have the same issue

@abramchikd commented on GitHub (Aug 17, 2025): I have the same issue
Author
Owner

@flow38 commented on GitHub (Nov 12, 2025):

Same problem here, a quick fix is to make your hook property nullable:

public MyType $data { set => $this->data = someAationOnValue($value)); }
Become
public ?MyType $data { set => $this->data = someAationOnValue($value)); }

@flow38 commented on GitHub (Nov 12, 2025): Same problem here, a quick fix is to make your hook property nullable: ` public MyType $data { set => $this->data = someAationOnValue($value)); }` Become ` public ?MyType $data { set => $this->data = someAationOnValue($value)); }`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7533