interface的使用和说明.php discount;}function getUserType(){return "VIP用户";}}//商品类class Goods{ var $price = 100; var $vc; //定义 User 接口类型参数,这时并不知道是什么用户 function run($vc){ $this-vc = $vc;
discount; } function getUserType(){ return "VIP用户"; } } //商品类 class Goods{ var $price = 100; var $vc; //定义 User 接口类型参数,这时并不知道是什么用户 function run($vc){ $this->vc = $vc; $discount = $this->vc->getDiscount(); $usertype = $this->vc->getUserType(); echo $usertype."商品价格:".$this->price*$discount; } } //调用案例 $Goods = new Goods(); $Goods->run(new VipUser); ?>