コード例 #1
0
ファイル: index.php プロジェクト: GarenGoh/test
    echo '$class 是MyClass类的实例对象';
}
echo "<hr/>";
//clone 关键词
$p1 = new person("张三", "男", "88");
$p2 = clone $p1;
$p1->name = "王麻子";
echo "<br/>";
echo $p1->name;
echo $p2->name;
echo "<hr/>";
//魔术方法 __toString() ————让 'echo $p1'不报错
echo $p1;
echo "<hr/>";
//魔术方法 __call()
$p1->run();
echo '<br/>';
$p1->say('爬', '开');
class DB
{
    private $sql = array("field" => "", "where" => "", "order" => "", "limit" => "", "group" => "", "having" => "");
    function __call($DBName, $args)
    {
        $DBName = strtolower($DBName);
        if (array_key_exists($DBName, $this->sql)) {
            $this->sql[$DBName] = $args[0];
        } else {
            echo '你调用的' . get_class($this) . '中的方法' . $DBName . '不存在!';
        }
        return $this;
    }