code: public static function getCausalChain(Exception $exception) : ArrayObject
      {
          $result = new ArrayObject();
          while ($exception !== null) {
              $result[] = $exception;
              $exception = $exception->getPrevious();
          }
          return $result;
      }
docs: Gets an {@link Exception} cause chain as an {@link ArrayObject}.
  The first entry in the list will be $exception followed by its cause hierarchy.
  
  @param Exception $exception
  @return ArrayObject