Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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
PHP特征碰撞构造函数_Php_Traits - Fatal编程技术网

PHP特征碰撞构造函数

PHP特征碰撞构造函数,php,traits,Php,Traits,抱歉,如果这是重复的,我以前确实搜索过答案 我正在努力重载trait中定义的方法。它抛出一个致命错误: 致命错误:配置有冲突的构造函数定义,这些定义来自第18行Configuration.php中的traits 他们的班级 看起来他们的\rtrait\Configuration和他们的\Package\Configuration都有构造函数,并且构造函数签名不兼容。(但如果没有两者的代码,很难说。) 如果theres\Package\Configuration确实打算与theres\therir

抱歉,如果这是重复的,我以前确实搜索过答案

我正在努力重载trait中定义的方法。它抛出一个致命错误:

致命错误:配置有冲突的构造函数定义,这些定义来自第18行Configuration.php中的traits

他们的班级


看起来
他们的\rtrait\Configuration
他们的\Package\Configuration
都有构造函数,并且构造函数签名不兼容。(但如果没有两者的代码,很难说。)


如果
theres\Package\Configuration
确实打算与
theres\therirtrait\Configuration
一起使用,您应该给他们写一份错误报告。否则,我想应该有一些关于如何在代码中使用类和trait的文档,这样它们就不会产生错误。

您可以像这样解决构造函数冲突

trait MyTrait {

    use BaseSomeTrait{
        BaseSomeTrait::__construct as private __otherConstruct;
    }

    public function __construct(/* maybe params here*/)
    {
        // maybe other code
        $this->__otherConstruct(/* maybe params here*/);
        // maybe other code
    }
}

如果MyClass也有一个构造函数,您需要在那里另外做,或者只有在MyTrait没有构造函数的情况下才在那里做…

谢谢,我最初是这样做的。原来是另一个更深层次的课程带来了依赖性。