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

[Serializer] Typed property Proxies\__CG__\App\Entity\Website::$ must not be accessed before initialization (in __sleep) #38274

Closed
allan-simon opened this issue Sep 23, 2020 · 5 comments

Comments

@allan-simon
Copy link

Symfony version(s) affected: 5.1.5

php version 7.4.3

Description

When login in my website , it produces this exception

Error:
Typed property Proxies\__CG__\App\Entity\Website::$ must not be accessed before initialization (in __sleep)

  at vendor/symfony/security-http/Firewall/ContextListener.php:178
  at serialize()
     (vendor/symfony/security-http/Firewall/ContextListener.php:178)
  at Symfony\Component\Security\Http\Firewall\ContextListener->onKernelResponse()
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor/symfony/http-kernel/HttpKernel.php:190)
  at Symfony\Component\HttpKernel\HttpKernel->filterResponse()
     (vendor/symfony/http-kernel/HttpKernel.php:136)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/http-kernel/HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:196)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (public/index.php:28)                

How to reproduce
no real idea

Possible Solution
no idea too :(

Additional context

it seems related to this PR #36332 , but unfortunately I still have this problem

@BoShurik
Copy link
Contributor

Is this entities somehow related to user (UserInterface)?

@allan-simon allan-simon changed the title [Serializer] Typed property Proxies\__CG__\App\Entity\File::$ must not be accessed before initialization (in __sleep) [Serializer] Typed property Proxies\__CG__\App\Entity\Website::$ must not be accessed before initialization (in __sleep) Sep 23, 2020
@allan-simon
Copy link
Author

yes

<?php
declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * @ORM\Entity()
 * @UniqueEntity(fields="email", message="email_already_taken")
 * @ORM\HasLifecycleCallbacks
 *
 */
class Customer implements UserInterface
{
   use HasId;
   use HasCreationAndUpdateTime;


    /**
     * @ORM\ManyToOne(targetEntity=Website::class)
     * @ORM\JoinColumn(nullable=true)
     */
    private ?Website $defaultWebsite;
}

@BoShurik
Copy link
Contributor

BoShurik commented Sep 23, 2020

Just implement \Serializable with only necessary fields

public function serialize()
{
    return serialize([
        $this->id,
        $this->enabled,
        $this->username,
        $this->password,
    ]);
}

public function unserialize($serialized)
{
    [
        $this->id,
        $this->enabled,
        $this->username,
        $this->password,
    ] = unserialize($serialized);
}

@allan-simon
Copy link
Author

thanks i'm trying that right now !

@allan-simon
Copy link
Author

I confirm it fixed the problem, thanks a lot :)

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

No branches or pull requests

4 participants