php封装练习

<body>
<?php

class jisuan
{
    private $a;
    private $b;
    
    function __construct($a,$b)
    {
        $this->a = $a;
        $this->b = $b;
    }
    
    function __set($d,$e)
    {
        if($e>0 and $e<100)
        {
            $this->$d=$e;
        }
    }
    function __get($d)
    {
        return $this->$d;
    }
    
    function he()
    {
        return $this->a+$this->b;
        }
    function ji()
    {
        return $this->a*$this->b;
        }
    
    
}

$c=new jisuan(10,20);

echo $c->he();
echo "<br>";
echo $c->ji();

?>
</body>
View Code

 

posted @ 2016-06-05 20:04  哔哩哔哩干杯  阅读(101)  评论(0编辑  收藏  举报