Better error handling in core PHP functions using Safe PHP

1 · Amit Merchant · Aug. 13, 2019, 1:22 p.m.
Some of the PHP’s core functions are designed in such a way that they do not handle exceptions in a better way. Instead, they just return false if there’s any error. This makes developers to handle those error themselves. Take the example below. $content = file_get_contents('foobar.json'); $foobar = json_decode($content); Here in the above code, if there’s no file named foobar.json, then file_get_contents will return false. Similarly, if the file content in $content is not valid JSON then json_...