Class Table Inheritance remove entity throws unexpected typed property error on PHP 7.4 #6432

Open
opened 2026-01-22 15:33:12 +01:00 by admin · 0 comments
Owner

Originally created by @bertoost on GitHub (Mar 24, 2020).

Bug Report

Q A
BC Break yes/no?
Version 2.7.1
PHP 7.4.3

Summary

I am using the Class Table inheritance as described here; https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html#class-table-inheritance
but when removing an entity, a typed property error is thrown.

Current behavior

When I create a new entity, this is working as expected. The records in both tables are created and linked to eachother.
But when I want to remove a sub-entity, it throws me an error;

Typed property App\Entity\Tenant\Person::$id must be string, null used

Expected behavior

I expect both records (in the main and sub-table) are removed like when it's created.

Classes

<?php

namespace App\Entity\Tenant;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({
 *     "student"="Student"
 * })
 */
abstract class Person
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="UUID")
     * @ORM\Column(type="guid", unique=true)
     */
    private string $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private ?string $firstName;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private ?string $lastName;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private ?string $email;

    // public setters and getters here...
}
<?php

namespace App\Entity\Tenant;

use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class Student extends Person
{
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private ?string $firstNames;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private ?string $initials;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private ?string $address1;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private ?string $address2;

    /**
     * @ORM\Column(type="string", length=10, nullable=true)
     */
    private ?string $zipCode;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private ?string $city;

    /**
     * @ORM\Column(type="string", length=2, nullable=true)
     */
    private ?string $country;

    /**
     * @ORM\Column(type="string", length=15, nullable=true)
     */
    private ?string $phone;

    /**
     * @ORM\Column(type="string", length=15, nullable=true)
     */
    private ?string $mobile;

    /**
     * @ORM\Column(type="date", nullable=true)
     */
    private ?DateTimeInterface $birthDate;

    /**
     * @ORM\Column(type="string", length=1, nullable=true)
     */
    private ?string $gender;

    // public setters and getters here...
}
Originally created by @bertoost on GitHub (Mar 24, 2020). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes/no? | Version | 2.7.1 | PHP | 7.4.3 #### Summary I am using the Class Table inheritance as described here; https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html#class-table-inheritance but when removing an entity, a typed property error is thrown. #### Current behavior When I create a new entity, this is working as expected. The records in both tables are created and linked to eachother. But when I want to remove a sub-entity, it throws me an error; ``` Typed property App\Entity\Tenant\Person::$id must be string, null used ``` #### Expected behavior I expect both records (in the main and sub-table) are removed like when it's created. #### Classes ```php <?php namespace App\Entity\Tenant; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap({ * "student"="Student" * }) */ abstract class Person { /** * @ORM\Id() * @ORM\GeneratedValue(strategy="UUID") * @ORM\Column(type="guid", unique=true) */ private string $id; /** * @ORM\Column(type="string", length=255) */ private ?string $firstName; /** * @ORM\Column(type="string", length=255) */ private ?string $lastName; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $email; // public setters and getters here... } ``` ```php <?php namespace App\Entity\Tenant; use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() */ class Student extends Person { /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $firstNames; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $initials; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $address1; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $address2; /** * @ORM\Column(type="string", length=10, nullable=true) */ private ?string $zipCode; /** * @ORM\Column(type="string", length=255, nullable=true) */ private ?string $city; /** * @ORM\Column(type="string", length=2, nullable=true) */ private ?string $country; /** * @ORM\Column(type="string", length=15, nullable=true) */ private ?string $phone; /** * @ORM\Column(type="string", length=15, nullable=true) */ private ?string $mobile; /** * @ORM\Column(type="date", nullable=true) */ private ?DateTimeInterface $birthDate; /** * @ORM\Column(type="string", length=1, nullable=true) */ private ?string $gender; // public setters and getters here... } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6432