PHP如何实现静态的链式调用

Db::table('**')->where('***','***')->order('***')->find('**');
想这种应该怎么实现
public function table()
{
    return new self();
}

示例:

<?php
class Db
{
    public $table;
    
    public $a;
    
    public $b;

    public static function table($table)
    {
        $db = new static;
        $db->table = $table;
        return $db;
    }
    
    public function where($a, $b)
    {
        $this->a = $a;
        $this->b = $b;
        return $this;
    }
}

Db::table('abc')->where('a', 'b');

来源:https://segmentfault.com/q/1010000019451768/

posted @ 2019-07-19 15:59  浮尘微光  阅读(649)  评论(0)    收藏  举报