php-enumeration
php-enumeration copied to clipboard
Autoloader bug when used with Doctrine and Annotations.
Doctrine is using manually require_once
and if it happens Enum class to be in Entity folder - It bypasses the autoloader and __constructStatic is never called.
https://github.com/doctrine/persistence/blob/2.1.x/lib/Doctrine/Persistence/Mapping/Driver/AnnotationDriver.php#L234
I don't have idea how to fix it generally. For quick fix in my code i did intermediate class.
final class EntityEnum extends NonEntityEnum
{
}
abstract class NonEntityEnum extends Enumeration
{
public static EntityEnum $value;
protected static function initializeValues(): void
{
self::$value = new EntityEnum();
}
}
so when Doctrine require_once 'EntityEnum.php';
it will lead autoloader to NonEntityEnum
and it will call the constructStatic.
I discovered that this method usually break up randomly. so I ended up like that:
EntityEnum.php
<?php
declare(strict_types=1);
class_alias(NonEntityEnm::class, 'EntityEnum');
@Warxcell thanks for the bug report. I will find out how to solve it for you.
In general, I'm going to suspend the whole development of this repository but will keep updates for people who already using it. I've mentioned it here as well: https://github.com/dbalabka/php-enumeration/issues/17#issuecomment-781670458
I doubt it there is a fix for that. At least I couldn't figure it out. Just posted here to be known for everybody. :)