像codeigniter一样扩展类函数

If you use codeigniter (maybe other framework too) , you can use something like this

$this->db->query()->row();

Now, i want to create something like that . For now , i have this simple class

class Users
{
    function getUser(){

    }
}

so, when i'm trying my class above i can use this

<?php
require 'Users.php';
$users= new Users();
$users->getUser();

but, what i want is. I can add order in my function. So maybe i can create like this

<?php
require 'Users.php';
$users= new Users();
$users->getUser()->orderby("fullname","asc");

how can i achieve that ? thanks in advance

This is called method chaining. For it to work, each method returns an object, which may be the same object.

Example:

class Users
{
    function getUser(){
        return new User();
    }
}

If you use:

<?php
require 'Users.php';
$users= new Users();
$users->getUser()->orderby("fullname","asc");

getUser will be called on Users and orderby will be called on User.