| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Issue type | Bug |
| Plugin | Php Inspections (EA Extended), 3.0.6.1 |
| Language level | PHP 7.2 |
Here is some example code:
namespace Demo\Test;
use Exception;
class Demo
{
public function illustrateBugReport()
{
throw new Exception('Invalid context specified.');
}
}
When using the suggested fix from the "General '\Exception' is thrown" inspection, the line that throws the exception gets replaced by this:
throw new RuntimeException('Invalid context specified.');
But obviously this will break the code, as Demo\Test\RuntimeException does not exist (class with a name in that namespace).
The correct fix would be to either use the fully qualified name for RuntimeException here, that would be:
throw new \RuntimeException('Invalid context specified.');
OR alternatively import RuntimeException as well. Like this:
namespace Demo\Test;
use RuntimeException;
class Demo
{
public function illustrateBugReport()
{
throw new RuntimeException('Invalid context specified.');
}
}
Confirmed, the easiest way will be to follow throw new \RuntimeException(...); approach. Thank you for reporting @andreasschroth.
Fixed!