Is this way to deal with errors safe in PHP ? Is it idiomatic? -
Is this way to deal with errors safe in PHP ? Is it idiomatic? -
i'm writing lot of code in few of functions :
$f = fopen($fname); if ($f === false) { throw new exception("cannot open $fname"); }
this verbose when deal lot of file open & deal with. i'm wondering if can work without unforeseen bad side-effect :
$f = fopen($fname) or die("cannot open $fname");
this idiomatic in perl, right in php ? there another, improve way ? seems valid, know php can bite in lot of unexpected ways.
i tend opt like:
if(!($f = @fopen($fname, 'r'))) { throw new exception("cannot open $fname"); }
the perl-style fine too, although believe fopen raise errors.
php error-handling
Comments
Post a Comment