I see this line in my php.log
:
PHP Fatal error: Class 'MyNamespace\InvalidArgumentException' not found in <file> on line X
Line X contains this:
throw new InvalidArgumentException("Error");
It happens on the page reload. First, I put some values into a form, click submit and my page loads. I click Refresh Page (using my browser functions) to reload the page and this is where I get the error.
Maybe when I refresh the page, a different codepath is executed. But still I deem this to be a native PHP class that should always work, but in my case it throws the error.
I am using PHP, Apache2 on Windows, originally installed via Zend Studio IDE suite.
The class description itself does not offer me any hints. Why does it throw the error and how do I fix it?
UPDATE*
My code is:
if (!isset($modelNumber)) //$modelNumber is NULL when I refresh
throw new InvalidArgumentException("Error");
So it is whenever I hit this class I get this error. When I remove isset
line and just throw the class directly, it always gives me the error.
You are using a namespace for the class that the exception is being thrown from. Because of this, PHP is looking for a class called "InvalidArgumentException" within that namespace. However, the InvalidArgumentException exists in the Global Namespace. Therefore, in order to access it, simply prepend a backslash before the exception:
throw new \InvalidArgumentException("Error");
Try adding a backslash before.
throw new \InvalidArgumentException("Error");
Try using
use http\Exception\InvalidArgumentException;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With