<?php
class mycoach
{
public $name="陈培昌";
CONST hisage =22;
public static $earnfor =2789;
private $favorite = "喜欢丁大锅";
public function __construct()
{
echo "{$this->name}到目前为止,为馆里卖出的装备价值".mycoach::$earnfor."元".PHP_EOL;
}
public static function declare()
{
echo "关灯吧,丁大锅,今天玩得太累了".PHP_EOL;
}
}
$cpc = new mycoach();
mycoach::declare();
?>
静态属性和方法属于类,具体的意义是,如果一些属性适合共享,那么就没必要每个对象都实例化一份,那样会造成空间的浪费,换句话无论有多少对象,静态属性就一份
静态属性访问方法----类名::属性