range

If there were you, the world would be just right

<?php

/**
 * 链式调用方式
 * Class Myreques
 */
class Myreques{

    private $do = false;

    private $resul;

    public function if($bool=false)
    {
        $this->do = $bool;
        return clone $this;
    }

    public function then(callable $func)
    {
        if($this->do){
            $this->resul = $func();
            $this->do = !$this->do;
        }
        return clone $this;
    }

    public function getResul()
    {
        return $this->resul;
    }
}
$req = new Myreques();
$true = true;
$p = json_decode('{"name":"Chinese"}');
$res = $req->if($true)
            ->then(function () use($p){
                return $p->name;
            })
            ->getResul();
print_r($res);