Example #1
0
        return 'blue';
    }
}
class Pink
{
    public function getColor()
    {
        return 'pink';
    }
}
error_reporting(E_ALL);
$show = new Show();
$red = new Red();
$blue = new Blue();
$pink = new Pink();
$show->say($red);
$show->say($blue);
//Catchable fatal error: Argument 1 passed to Show::say() must be an instance of Light, instance of Pink given
//$show->say($pink);
//静态方法和属性在类声明时被定义,且所有的对象共同拥有,调用类的静态方法或属性用  类名::方法名/$属性名,不依赖于对象。对于动态方法、变量不能这样使用。
class Hello
{
    public static $num = 0;
    public static function say()
    {
        echo Hello::$num;
        echo '<br/>';
    }
    public function tell()
    {
        Hello::say();