abstract:<?php # static 关键字 # 1. 定义与访问类静态成员 # 2. 访问类常量 # 3. 后期静态绑定 class MyClass { const NATION = '中国'; protected static $name
<?php # static 关键字 # 1. 定义与访问类静态成员 # 2. 访问类常量 # 3. 后期静态绑定 class MyClass { const NATION = '中国'; protected static $name; protected static $age; protected static $sex; public function __construct($name,$age,$sex) { self::$name = $name; self::$age = $age; self::$sex = $sex; } } class Sub extends MyClass { public function __construct($name,$age,$sex) { parent::__construct($name,$age,$sex); } public static function getInfo() { echo '国际: '.static::NATION,'<br>'; echo '姓名: '.static::$name,'<br>'; echo '年龄: '.static::$age,'<br>'; echo '性别: '.static::$sex; } public static function setInfo($name, $age, $sex) { static::$name = $name; static::$age = $age; static::$sex = $sex; } } new Sub('Amy',18,'女'); echo Sub::getInfo(),'<hr>'; Sub::setInfo('Jerry', 20, '男'); echo Sub::getInfo(),'<hr>'; # Sub::NATION = '美国'; # 常量不能被修改 echo Sub::NATION;
Correcting teacher:查无此人Correction time:2019-04-30 09:08:43
Teacher's summary:完成的不错。php的类学完后,就相当于入门了。继续加油。