Chaining Static Methods in PHP?

前端 未结 16 2119
情歌与酒
情歌与酒 2020-11-27 14:25

Is it possible to chain static methods together using a static class? Say I wanted to do something like this:

$value = TestClass::toValue(5)::add(3)::subtrac         


        
16条回答
  •  囚心锁ツ
    2020-11-27 14:42

    Fully functional example of method chaining with static attributes:

    send(['error' => $msg_error], $http_code);
        }
    }
    

    Example of use:

    Response::getInstance()->code(400)->sendError("Lacks id in request");
    

提交回复
热议问题