<?php
namespace _1010;
class A
{
public static function who()
{
echo __CLASS__;
}
public static function test()
{
static::who();
}
}
class B extends A
{
public static function who()
{
echo __CLASS__;
}
}
A::test();
echo '<br>';
B::test();
echo '<hr>';
class Connect
{
public static function connect()
{
return static::config();
}
public static function config()
{
return new \PDO('mysql:dbname=php;host=127.0.0.1', 'root', '123456');
}
}
class Link extends Connect
{
public static function config()
{
return new \PDO('mysql:dbname=php;host=127.0.0.1', 'root', 'root');
}
}
$pdo = Link::connect();
foreach ($pdo->query('select * from staff limit 5') as $staff) {
print_r($staff); echo '<br>';
}
php静态绑定的主要目的是动态调用方法
|