使用子类,我将如何使我的代码工作?

问题描述

我正在扩展 Bankrekening 并向其添加变量 $rente,$rente 的值应由函数 BerekenRente() 确定,该函数不使用任何参数且不需要在构造函数参数中进行初始化从我的理解。我收到此错误:

解析错误:语法错误,在 C:\xampp\htdocs\SpaarBetaalrekening.php 中第 55 行出现意外的 '(',期望变量 (T_VARIABLE)

这指的是这一行: 公共函数 __construct($naam,$rekeningnummer,$saldo,$kredietlimiet) {

class Spaarrekening extends Bankrekening{
    var $rente;

    public function __construct($naam,$kredietlimiet) {
        $this->naam = $naam;
        $this->rekeningnummer = $rekeningnummer;
        $this->saldo = $saldo;
        $this->kredietlimiet = $kredietlimiet;
        $this->rente = BerekenRente();
    }

    //Ontvang rente
    function OntvangRente(){
        $this->saldo = $saldo + BerekenRente();
    }

    function BerekenRente(){
        return ($this->saldo / 100) * 0.30;
    }
}

$rekening1 = new Spaarrekening("James",5543,600,2000);
echo $rekening1->saldo;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)