利用后期静态绑定技术,实现在父类调用子类中重写的静态成员
七友2019-04-08 11:22:29275<?php
/**
* Created by PhpStorm.
* User: hp
* Date: 2019/4/8
* Time: 10:09
*/
class Boy
{
public static $money = 10000;
public static function getClass()
{
return __CLASS__;
}
public static function getMoney()
{
return static::getClass().'赚了'.static::$money.'元';
}
}
class Girl extends Boy
{
public static $money = 7000;
public static function getClass()
{
return __CLASS__;
}
}
echo Boy::getClass(),'<br>';
echo Boy::getMoney(),'<br>';
echo Girl::$money,'<br>';
echo Girl::getClass(),'<br>';
echo Girl::getMoney();