1

I'm migrating from php 7.4 to 8.1. Other versions are: PHP 8.1, Doctrine 2.13, Symfony 5.4, ApiPlatform 2.7, myclabs/php-enum 1.8.

I've updated my code to use baked enums as said here: https://www.doctrine-project.org/2022/01/11/orm-2.11.html . But now don't understand how to use it.

Without Type::addType method i just have error Unknown column type requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType().

With \Doctrine\DBAL\Types\Type::addType(MyEnum::class, MyEnum::class) i get error Cannot instantiate enum MyEnum.

Didn't find any docs in Doctrine website actually. All they have is just this: https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/cookbook/mysql-enums.html but docs not using php8 at all (no native enums, no attributes, etc). I'm confused.

Entity part of code (same errors with any entity of my project):

<?php

namespace App\Entity;

use App\Enum\FooStatus;
use App\Repository\FooRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: FooRepository::class)]
class Foo
{
    #[Column(type: 'string', enumType: FooStatus::class)]
    protected FooStatus $status;
}
trogwar
  • 216
  • 1
  • 11
  • 26
  • 1
    I've written a full blog post on the subject, maybe you will find hints in it: https://www.strangebuzz.com/en/blog/using-php-8-1-enumerations-in-a-symfony-project But, yes it should work. Try to add a default value on `protected FooStatus $status`. – COil Oct 08 '22 at 15:27

0 Answers0