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

Compile Error - Proxy not compatible with entity class on PHP 7.1 #6421

Closed
jazithedev opened this issue May 3, 2017 · 7 comments
Closed
Assignees

Comments

@jazithedev
Copy link

jazithedev commented May 3, 2017

[Symfony\Component\Debug\Exception\FatalErrorException]
Compile Error: Declaration of Proxies_CG_\Project\UserBundle\Entity\Role::__construct($initializer = NULL, $cloner = NULL) must be compatible with Project\LocaleBundle\Locale\EntityExt\LocalesInterface::__construct(?Project\LocaleBundle\Locale\EntityExt\Locales $locale = NULL)

Proxy:

<?php

namespace Proxies\__CG__\Project\UserBundle\Entity;

/**
 * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
 */
class Role extends \Project\UserBundle\Entity\Role implements \Doctrine\ORM\Proxy\Proxy
{
    /**
     * @var \Closure the callback responsible for loading properties in the proxy object. This callback is called with
     *      three parameters, being respectively the proxy object to be initialized, the method that triggered the
     *      initialization process and an array of ordered parameters that were passed to that method.
     *
     * @see \Doctrine\Common\Persistence\Proxy::__setInitializer
     */
    public $__initializer__;

    /**
     * @var \Closure the callback responsible of loading properties that need to be copied in the cloned object
     *
     * @see \Doctrine\Common\Persistence\Proxy::__setCloner
     */
    public $__cloner__;

    /**
     * @var boolean flag indicating if this object was already initialized
     *
     * @see \Doctrine\Common\Persistence\Proxy::__isInitialized
     */
    public $__isInitialized__ = false;

    /**
     * @var array properties to be lazy loaded, with keys being the property
     *            names and values being their default values
     *
     * @see \Doctrine\Common\Persistence\Proxy::__getLazyProperties
     */
    public static $lazyPropertiesDefaults = [];



    /**
     * @param \Closure $initializer
     * @param \Closure $cloner
     */
    public function __construct($initializer = null, $cloner = null)
    {

        $this->__initializer__ = $initializer;
        $this->__cloner__      = $cloner;
    }


//  [...]
}

Entity:

/**
 * @ORM\Entity
 * @ORM\Table(name="users_roles")
 */
class Role extends EntityWithLocales implements RoleInterface
{
//  [...]

    /**
     * Role constructor.
     *
     * @param Locales|null $locale
     */
    public function __construct(Locales $locale = null)
    {
        $this->users   = new Collections\ArrayCollection();
        $this->locales = new Collections\ArrayCollection();

        parent::__construct($locale ?? new RoleLocale());
    }
//  [...]
}

Above occurs when I'm using Doctrine Fixtures and method getReference(). Everything is okay (no errors like above) when I just traverse trough the project pages or do not use above method in Fixtures.

I got similar problem in other case:
https://stackoverflow.com/questions/43521985/symfony-3-doctrine-proxy-error-after-entity-magic-method-change-with-php-7-t

PHP 7.1 here.

@Ocramius
Copy link
Member

Ocramius commented May 3, 2017

What's your doctrine/common version? Please upgrade to latest.

@jazithedev
Copy link
Author

@Ocramius

Part of my composer.json file:

        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "doctrine/orm": "^2.5",

In my composer.lock there is v2.7.2 of doctrine/common.

@Ocramius
Copy link
Member

Ocramius commented May 3, 2017

Wait, your LocalesInterface#__construct() is interfaced? I'm afraid there's nothing we can do for this right now. The only solution will be to switch to ProxyManager at some point (#1241).

This is a limitation of the library that can't be fixed in 2.x

@Ocramius Ocramius added this to the 3.0 milestone May 3, 2017
@jazithedev
Copy link
Author

So I presume, that this also applies for all magic methods?
In THIS example I tried to define PHP7 types in __get.

@Ocramius
Copy link
Member

Ocramius commented May 3, 2017

@ktrzos magic methods are usually fixed/predefined, so even if you interface them, usually everything is fine.

In general, #1241 fixes all these concerns, but it won't be ready for a while...

@Ocramius
Copy link
Member

Ocramius commented May 4, 2017

@ktrzos for the magic method definitions, Ocramius/ProxyManager#350 is relevant.

@Majkl578
Copy link
Contributor

Doctrine 3.0 will be switching to ProxyManager so this issue could be closed.

@Majkl578 Majkl578 self-assigned this Dec 11, 2017
@greg0ire greg0ire removed this from the 3.0.0 milestone Jun 27, 2021
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