<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Static
*
* @author admin
*/
class StaticTest {
public static $name="wwj848987121";
public function getusername(){
echo self::$name."<br/>";
}
}
class Son extends StaticTest{
function myname(){
echo self::$name."<br/>";
}
}
StaticTest::getusername();
Son::myname();
Son::getusername();
$StaticTest=new StaticTest();
$StaticTest->getusername();
//$StaticTest->$name 错误的调用方法
/**
* static 关键字定义的成员属性可以不需要构造直接访问。但是不可以用$this->$name的方法进行调用,而static定义的方法则可以进行实例化后进行$this->getusername();进行访问
* 输出的结果为:
* wwj848987121
wwj848987121
wwj848987121
wwj848987121
*/