Elegant ways to return multiple values from a function

后端 未结 14 893
梦谈多话
梦谈多话 2020-12-15 03:49

It seems like in most mainstream programming languages, returning multiple values from a function is an extremely awkward thing.

The typical soluti

14条回答
  •  无人及你
    2020-12-15 04:51

    Often in php I'll use a referenced input:

    public function Validates(&$errors=array()) {
       if($failstest) {
          $errors[] = "It failed";
          return false;
       } else {
          return true;
       }
    }
    

    That gives me the error messages I want without polluting the bool return, so I can still do:

    if($this->Validates()) ...
    

提交回复
热议问题