Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
symfony2实体上的PHP多重继承。正道_Php_Oop_Symfony_Multiple Inheritance - Fatal编程技术网

symfony2实体上的PHP多重继承。正道

symfony2实体上的PHP多重继承。正道,php,oop,symfony,multiple-inheritance,Php,Oop,Symfony,Multiple Inheritance,我有两个抽象类:AbstractCommentable(用于注释的方法)和AbstractImaging(用于管理图像的实体方法) 有些课程已经有: class Trip extends AbstractImaging {/** some stuff **/} class Marker extends AbstractImaging {/** some stuff **/} class Gastronomy extends AbstractImaging {/** some stuff **/}

我有两个抽象类:AbstractCommentable(用于注释的方法)和AbstractImaging(用于管理图像的实体方法)

有些课程已经有:

class Trip extends AbstractImaging {/** some stuff **/}
class Marker extends AbstractImaging {/** some stuff **/}
class Gastronomy extends AbstractImaging {/** some stuff **/}
但是我想把AbstractCommentable添加到这个类中


正确的方法是什么?

你要么让
AbstractImaging
已经扩展了
AbstractCommentable
,要么用其他方法。。。我建议你不要

由于可能存在冲突,PHP中的多重继承只能是线性的

你不能做像

class Whatever extends AbstractImaging, AbstractCommentable
简单的方法:

如果您使用的是PHP5.4+,那么可以使用trait将CommentableInterface方法添加到实体中

复杂的方式:


创建一个注释,让条令侦听器创建一个代理类,添加可注释的方法。

您要么必须使
AbstractImaging
已经扩展
AbstractCommentable
,要么通过其他方式。。。我建议你不要

由于可能存在冲突,PHP中的多重继承只能是线性的

你不能做像

class Whatever extends AbstractImaging, AbstractCommentable
简单的方法:

如果您使用的是PHP5.4+,那么可以使用trait将CommentableInterface方法添加到实体中

复杂的方式:


创建一个注释,让条令侦听器创建一个代理类,添加可注释的方法。

复杂的方法看起来更好。。。我将尝试最终我创造了我自己的行为(特征)jeah这是一种快速的方法,并在一些捆绑中使用,比如KnpDoctrineBehaviors。。。虽然无法顺利测试:但现在的问题是。。。trait Commentable有一个@ORM\OneToMany(targetEntity=“Comment”,mappedBy=“???????”),我不能设置mappedBy-(复杂的方式看起来更好…我将尝试最终创建我自己的行为(特征)jeah这是一种快速的方式,也用于一些捆绑包中,如KnpDoctrineBehaviors…虽然无法顺利测试:D现在的问题是…可注释的特征有一个@ORM\OneToMany(targetEntity=“Comment”,mappedBy=“??”)我无法设置mappedBy-(