Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum - XXX::from(): Argument #1 ($value) must be of type string, XXX given #10069

Closed
bastien70 opened this issue Sep 27, 2022 · 0 comments
Closed

Comments

@bastien70
Copy link

bastien70 commented Sep 27, 2022

BC Break Report

Q A
BC Break yes
Version 2.13.2

Summary

After upgraded to the latest version, we are having trouble hydrating entities containing an enum, after a DQL query

Current behavior

App\Entity\Enum\ArticleState::from(): Argument #1 ($value) must be of type string, App\Entity\Enum\ArticleState given

How to reproduce

  1. Create the entity
class Article
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255, enumType: ArticleState::class)]
    private ?ArticleState $state = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getState(): ?ArticleState
    {
        return $this->state;
    }

    public function setState(ArticleState $state): self
    {
        $this->state = $state;

        return $this;
    }
}
  1. Create the enum
enum ArticleState: string
{
    case ONLINE = 'online';
    case OFFLINE = 'offline';
}
  1. Add the repository request
    /**
     * @return Article[]
     */
    public function findByState(ArticleState $articleState): array
    {
        return $this->createQueryBuilder('a')
            ->andWhere('a.state = :state')
            ->setParameter('state', $articleState->value)
            ->getQuery()
            ->getResult();
    }
  1. Try the request, and you will get this error :
App\Entity\Enum\ArticleState::from(): Argument #1 ($value) must be of type string, App\Entity\Enum\ArticleState given

Reproducer

https://github.com/bastien70/enum-reproducer

EDIT : duplicate of #10058

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant