我想从父类中定义的函数调用子类中定义的函数以实现某些逻辑。我收到未定义函数的错误。我怎么能调用这个函数。这是我的示例代码。
<?php
class First
{
public function __construct()
{
echo "First class is initiated.";
}
public function call_child()
{
$this->get_ouput();
}
}
class Second extends First
{
public function __construct()
{
parent::__construct();
}
public function get_output()
{
echo "Here is your output";
}
}
$obj = new Second();
$obj->call_child();
?>
问题是函数调用名称中的拼写错误
<?php
class First
{
public function __construct()
{
echo "First class is initiated.";
}
public function call_child()
{
$this->get_output(); //update the name here
}
}
class Second extends First
{
public function __construct()
{
parent::__construct();
}
public function get_output()
{
echo "Here is your output";
}
}
$obj = new Second();
$obj->call_child();
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句