如何通过引用父级传递对象?通过引用传递父级PHP类
我有以下脚本,并收到以下错误。
严格的标准:myChild :: myMethod的(声明)应 与myParent :: myMethod的($ ID = NULL,& $模式= NULL)在 在/ var/WWW/bidjunction/HTML /兼容测试/passbyreference.php第19行
<?php
class myParent
{
public function myMethod($id=null,&$model=null)
{
$model=$model?$model:new stdClass();
var_dump($model);
}
}
class myChild extends myParent
{
public function myMethod($id=null,$model=null)
{
$model=new stdClass();
$model->foo='bar';
parent::myMethod(123,$model);
}
}
class myOtherChild extends myParent{}
$myChild=new myChild();
$myChild->myMethod();
$myOtherChild=new myChild();
$myOtherChild->myMethod();
?>
你传递'$ model'由裁判在父,但不是孩子 – andrew 2014-12-03 13:05:43
@andrew。如何以孩子的参考为基础? – user1032531 2014-12-03 13:07:01
看看方法签名和你的错误应该很容易被发现 – PeeHaa 2014-12-03 13:10:50