<?php
/*静态属性用于保存内的公有数据
* 静态方法里面只能访问静态属性
* 静态成员不需要实例化就可以访问
* 类的内部可以通过self或者static关键字访问自身的静态成员
* 子内方法中可以通过parent关键字访问父类的静态成员
* 可以通过类的名称在类定义外部访问静态成员
*/
class Human{
public $name;
public $height;
public $weight;
public static $value= "this value is ture ";
static function valu(){
echo self::$value;
}
}
class NbaPlayer extends Human{
public $team;
public $playernumber;
public static $president= "DAVSID";
function __construct($name,$height,$weight,$team,$playernumber){
echo $this->name."jumping"."<br>";
$this->name=$name;
$this->height=$height;
$this->weight=$weight;
$this->team=$team;
$this->playernumber=$playernumber;
}
function jump(){
echo $this->name."jump"."<br>";
echo parent::valu()."<br>";//parent关键字在非静态方法中同样适用
}
static function changpresident($newpresident){
echo static::$president."<br>";
echo self::$president."<br>";//类的内部可以通过self或者static关键字访问自身的静态成员
echo self::$president=$newpresident."<br>";
echo parent::$value."<br>";//用parent关键字访问父类中的静态属性
echo parent::valu();//用parent关键字访问父类中的静态方法
//echo $this->name;$this只能用于实例化对象中;
}
}
NbaPlayer::changpresident("dad");//可以通过类的名称在类定义外部访问静态成员
$jodan=new NbaPlayer("jodan","203cm","120kg","bull","23");
echo $jodan->height;
$jodan->jump();
/*静态属性用于保存内的公有数据
* 静态方法里面只能访问静态属性
* 静态成员不需要实例化就可以访问
* 类的内部可以通过self或者static关键字访问自身的静态成员
* 子内方法中可以通过parent关键字访问父类的静态成员
* 可以通过类的名称在类定义外部访问静态成员
*/
class Human{
public $name;
public $height;
public $weight;
public static $value= "this value is ture ";
static function valu(){
echo self::$value;
}
}
class NbaPlayer extends Human{
public $team;
public $playernumber;
public static $president= "DAVSID";
function __construct($name,$height,$weight,$team,$playernumber){
echo $this->name."jumping"."<br>";
$this->name=$name;
$this->height=$height;
$this->weight=$weight;
$this->team=$team;
$this->playernumber=$playernumber;
}
function jump(){
echo $this->name."jump"."<br>";
echo parent::valu()."<br>";//parent关键字在非静态方法中同样适用
}
static function changpresident($newpresident){
echo static::$president."<br>";
echo self::$president."<br>";//类的内部可以通过self或者static关键字访问自身的静态成员
echo self::$president=$newpresident."<br>";
echo parent::$value."<br>";//用parent关键字访问父类中的静态属性
echo parent::valu();//用parent关键字访问父类中的静态方法
//echo $this->name;$this只能用于实例化对象中;
}
}
NbaPlayer::changpresident("dad");//可以通过类的名称在类定义外部访问静态成员
$jodan=new NbaPlayer("jodan","203cm","120kg","bull","23");
echo $jodan->height;
$jodan->jump();