标签:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <?php class Dog //定义类 { private $name; //定义变量,private封装 private $age; private $pinzhong; function Jiao() { echo "{$this->name}在叫,它{$this->age}岁"."<br>"; //this代表该对象,如果要在成员方法中, } //调用成员变量,一要使用$this找出该成员变量 function __construct($n,$a,$p) //构造函数 { $this->name = $n; $this->age =$a; $this->pinzhong = $p; } /*function __destruct() //析构函数,无参数, { echo "结束"; //{}方法随意写 }*/ function __set($name,$value) { $this->$name = $value; } function __get($name) { return $this->$name; } } class HaShiQi extends Dog //extends 继承 { const A = 9 ; //const 定义一个常量 public static $height; function Jiao() { parent::Jiao(); //类调用方法 类名加双冒号方法或变量:: echo "hello"; } static function Gao() { echo "这么高"; } } $dog = new Dog("旺财",10,"金毛"); $dog->name = "小强"; $dog->age = "6"; echo $dog->pinzhong."<br>"; $dog->Jiao(); //final class person{} //final 终类不能被继承 HaShiQi::$height=10; echo HaShiQi::$height; ?> </body> </html>
标签:
原文地址:http://www.cnblogs.com/sihuiming/p/5158869.html