在PHP中使用echo进行回声

时间:2016-09-25 19:32:00

标签: php class echo

我有这个代码。

$cislo1 = new Cislo(5);
$cislo2 = $cislo1->odecti(2)->pricti(5);

这段代码。

class Cislo
{
  public function __construct($cislo1)
  {
    $this->cislo1 = $cislo1;
  }
public function pricti($cislo2)
{
  $this->cislo2 = $cislo2;
$cislo2 = $this->cislo1 + $this->cislo2;
}
public function odecti($cislo2)
{
$this->cislo2 = $cislo2;
$cislo2 = $this->cislo1 - $this->cislo2;
}
}

我如何制作echo类?我想我需要make echo Cislo。但不知道怎么办?

1 个答案:

答案 0 :(得分:0)

所以添加

Person

试试这个

public function __toString()
{
        return $this->cislo1;

有这个 Picture with error