What's the difference between TypeError and InvalidArgumentException in PHP 7?
When to throw TypeError and when to throw InvalidArgumentException?
It seems that the error is getting more like exception in PHP 7.
What's the border line that divides error and exception?
TypeError
occurs when the type of argument or returned value of a function doesn't match the expected type, for the example, if a function required a string
but you passed/returned int
.
InvalidArgumentException
can be used to throw error if the argument doesn't match the expected value, for example if you want the argument only has value in range 1 to 10, but the caller pass the value 11, you can throw this exception.
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