[UPHPU] @include_once bad?

Michael Jones jmjones at sisna.com
Fri Mar 27 10:45:41 MDT 2009


Daniel C. wrote:
> On Fri, Mar 27, 2009 at 9:40 AM, Kevin<email.bdr at gmail.com>  wrote:
>    
>> "Error suppression is slow. This is because PHP dynamically changes
>> error_reporting to 0 before executing the suppressed statement, then
>> immediately changes it back. This is expensive."
>>      
>
> Cool, I didn't know that.
>
>    
>> Using error suppression is always a bad thing. It makes debugging in the
>> future much more difficult. If you want to include only files that exist
>> just wrap it in an if ( file_exists($file) ). This makes the code much more
>> clearer [sic] and you don't sacrifice missing other potential errors that
>> include_once might throw.
>>      
>
> Aside from the slowness, I don't see how the two are different.
> Either way you're ensuring that include_once doesn't screw up your
> program.
>
>    
Essentially, you are acknowledging that there will likely be an error 
when including the file. By wrapping the include in a file_exists($file) 
function, you are actually handling the error, rather than just ignoring 
it.  Plus, this way you could have the code do something different if 
the file doesn't exist, whereas if you just ignore the error there is no 
way for the rest of the script to know whether or not the file was included.

> -Dan
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
>    



More information about the UPHPU mailing list