内部函数调用的结束函数 - PHP

I have a function which needs multiple checks and for that, I have added multiple functions but when some inner-function fails it needs to return the response as failed but it does not and continues the next inner-function

 public static function doMultipleWorks(){

  self::checkFirstCondition();
  self::checkSecondCondition();

  ...
  ...

  return response(['status' => true, 'data' => [...]]);

 }

 public static function checkFirstCondition(){

  ....
  ....
  if(this != that){
    return response(['status' => false, 'error_msg' => 'this is not equal to that']]
  }

 }

 public static function checkSecondCondition(){

  ....
  ....
  if(this != that){
    return response(['status' => false, 'error_msg' => 'this is not equal to that']]
  }


 }

The problem is that if the first or second function fails it still continues and it does not break out of the function. Any help would be highly appreciated.

You need to check the response of functions and on response bases, you should continue or break further processes. I believe you should do something like this:

public static function doMultipleWorks(){

  $firstResponse = self::checkFirstCondition();
  if ($firstResponse['status'] == false) {
       return $firstResponse;
  }
  $secondResponse = self::checkSecondCondition();
  if ($secondResponse['status'] == false) {
       return $secondResponse;
  }

  ...
  ...

  return response(['status' => true, 'data' => [...]]);

 }

 public static function checkFirstCondition(){

  ....
  ....
  if(this != that){
    return response(['status' => false, 'error_msg' => 'this is not equal to that']]
  }

 }

 public static function checkSecondCondition(){

  ....
  ....
  if(this != that){
    return response(['status' => false, 'error_msg' => 'this is not equal to that']]
  }


 }

Hope it helps you to fix your approach.

You are not checking the return value of checkFirst and checkSecond, do this or throw an exception instead to interrupt the function and try/catch the exception

public function foo() {
     if ($bar = $this->bar()) return $bar;
}

public function bar() {
   if (something) return resp;
}

public function foo() {
    try {
        $this->bar();
    }catch(\Exception $e) {
         return [ 'success' => false, 'status' => $e->getMessage(), ];
    }
}

public function bar() {
   if (something) throw new Exception('Fail');
}