Can only throw objects¶
Description¶
The throw keyword operates on exceptions, which are always objects. So, it is not possible to throw other types, such as integers, strings or arrays.
Example¶
<?php
throw 1;
?>
Solutions¶
Use
throw new Exception().Use
throw new Error().Use
throw $object, where $object contains an error or an exception.Use
throw ($object), where $object contains an error or an exception.