多重静态函数调用方法

时间:2018-09-20 09:59:17

标签: php class

当我使用static::find()函数时,我想返回数据库行结果。但是在另一种情况下,我想链接到一个新的类静态函数update()。例如static::find(1)->update(),需要这种情况return new static。我找不到确定需要哪种返回方法的条件。美好的一天。

class A {
    public static function find($id){

        global $db_link;

        $id = (integer)$id;

        if($id){

            $stmt = $db_link->prepare("select * from ".static::get_table_name()." where ".static::$primary_key." = :id limit 1");
            $stmt->execute([":id" => $id]);
            $return = $stmt->fetch(PDO::FETCH_ASSOC);

            if(!empty($return)){

                static::$primary_id[] = $return["id"];
                static::$data = $return;

            }

        }

        return new static;

        return static::format_success($return);

    }
}

0 个答案:

没有答案
相关问题