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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -