示例#1
0
    {
        $a = $this->a;
        $b = $this->b;
        $num = $a - $b;
        echo "{$a}-{$b}={$num}</br>";
    }
    function multiply()
    {
        $a = $this->a;
        $b = $this->b;
        $num = $a * $b;
        echo "{$a}*{$b}={$num}</br>";
    }
    function divide()
    {
        $a = $this->a;
        $b = $this->b;
        $num = $a / $b;
        echo "{$a}/{$b}={$num}</br>";
    }
    function __construct($a, $b)
    {
        $this->a = $a;
        $this->b = $b;
    }
}
$cal = new cal(5, 2);
$cal->add();
$cal->minus();
$cal->multiply();
$cal->divide();
示例#2
0
        $b = $this->b;
        if ($b == self::A) {
            echo $this->a . "</br>";
        } else {
            if ($b < self::A) {
                echo '$this->a' . '$this->b' . self::i . "</br>";
            } else {
                echo "{$this->a}+{$b}" . self::i . "</br>";
            }
        }
    }
}
class num extends cal
{
    public $a;
    public $b;
    public $num;
    const i = "i";
    function __construct($a, $b)
    {
        $this->a = $a;
        $this->b = $b;
        $this->num = "(" . "{$a}+{$b}" . self::i . ")";
    }
}
$num1 = new num(5, 2);
$num2 = new num(1, 2);
$cal = new cal();
$cal->add($num1, $num2);
$cal->minus($num1, $num2);