Почему PhpStorm показывает, что в коде ошибка, хотя в нем нет ошибки?

150
26 февраля 2018, 02:32

Есть вот такой фрагмент кода:

try {
    if (!class_exists($prefix . $controller)) {
        throw HTTP_Exception::factory(404, 'The requested URL :uri was not found on this server.', array(':uri' => $request->uri())
        )->request($request);
    }
  // Load the controller using reflection
  $class = new ReflectionClass($prefix . $controller);
  if ($class->isAbstract()) {
    throw new Kohana_Exception(
    'Cannot create instances of abstract :controller', array(':controller' => $prefix . $controller)
    );
  }
  // Create a new instance of the controller
  $controller = $class->newInstance($request, $response);
  // Run the controller's execute() method
  $response = $class->getMethod('execute')->invoke($controller);
  if (!$response instanceof Response) {
    // Controller failed to return a Response.
    throw new Kohana_Exception('Controller failed to return a Response');
  }
} catch (HTTP_Exception $e) {
  // Get the response via the Exception
  $response = $e->get_response();
} catch (Exception $e) {
  // Generate an appropriate Response object
  $response = Kohana_Exception::_handler($e);
}

PhpStorm помечает try ошибочным:

The thrown object must be an instance of the Exception or Throwable

Вот наследование:

HTTP_Exception - Kohana_HTTP_Exception - Kohana_Exception - Kohana_Kohana_Exception - Exception

Вот код request:

public function request(Request $request = NULL) {
    if ($request === NULL)
      return $this->_request;
    $this->_request = $request;
    return $this;
}

Это код фреймворка Kohana. Почему PhpStorm показывает, что в коде ошибка? Как мне это исправить?

Answer 1

Посмотрел на компьютере. Скопировал ваш пример, объявил пустые классы с указанным наследованием - ошибка пропала. У вас где-то синтаксис или опечатка.

Вот минимальный, самодостаточный и воспроизводимый пример: https://ru.stackoverflow.com/help/mcve

<?php
class Kohana_Exception extends Kohana_Kohana_Exception {
}
class Kohana_Kohana_Exception extends Exception {
}
try {
    throw new Kohana_Exception(
        'Cannot create instances of abstract :controller', array( ':controller' => $prefix . 'controller' )
    );
} catch ( Exception $e ) {
    die();
}

К этому коду у phpStorm одна претензия - два класса в одном файле. Других проблем нет.

READ ALSO
сортировка через get

сортировка через get

Есть таблица с пагинацией, которая работает параметром get значение которого подставляется в ссылки ( снизу на картинке )

171
Не считывает двумерный масив с формы

Не считывает двумерный масив с формы

Часть программы должна считывать двумерный массив и искать количество элементов равным 0Но, как я понял, оно даже полностью не считывает...

166
Реализация аутентификации через SMS (Laravel)

Реализация аутентификации через SMS (Laravel)

Всем приветДелаю систему аутентификации на Laravel через SMS

164