property conflict with parent class

I have this class ZghFEBundleEntityUser which extends FOSUserBundleModelUser .

use FOSUserBundleModelUser as BaseUser;

class User extends BaseUser implements ParticipantInterface
{
    use BasicInfo;
    // ..
}

And BaseUser class:

abstract class User implements UserInterface, GroupableInterface
{
    protected $id;
    // ..
}

And BaseInfo trait:

trait BasicInfo
{
    /**
     * @ORMColumn(type="string", length=255)
     * @ORMId
     * @ORMGeneratedValue(strategy="NONE")
     */
    protected $id;

    // ..
}

But when I run my code i get this error:

Strict standards: FOSUserBundleModelUser and ZghFEBundleModelPartialBasicInfo define the same property ($id) in the composition of ZghFEBundleEntityUser. This might be incompatible, consider using accessor methods in traits instead.

I'm using Symfony framework.

Is there anyway to resolve this conflict between the trait and the parent class object about this property ?


No, it's not yet possible to rewrite a mapped property by using a Trait.

Also, a possible alternative is to use multiple abstract entity classes, and extend your child entities depending on your need.

ie

<?php

use FOSUserBundleModelUser as BaseUser;

abstract class AbstractStrategyNoneEntity extends BaseUser
{
    /**
     * @ORMColumn(type="string", length=255)
     * @ORMId
     * @ORMGeneratedValue(strategy="NONE")
     */
    protected $id;
}

abstract class AbstractStrategyAutoEntity extends BaseUser
{
    /**
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     *
     */
    protected $id;
}

And extend one of them in your child entities.

/**
* @ORMEntity
*/
class Child extends AbstractStrategyNoneEntity 
{
    // Inherited mapping
}

Hopes this answers your question.

链接地址: http://www.djcxy.com/p/11906.html

上一篇: 什么是一个MySQL

下一篇: 与父类的财产冲突