|
Posted by Jerry Stuckle on 12/08/07 12:44
Toby A Inkster wrote:
> Jerry Stuckle wrote:
>
>> including a file which does not exist will not throw an exception.
>
> My general method is:
>
> $old_error_reporting = error_reporting(E_ERROR);
> include 'Foo.php';
> error_reporting($old_error_reporting);
>
> This will include a file without issuing any warnings if it's missing.
>
> And then you just perform a test to see if something that you know is
> defined in Foo.php has successfully been defined. e.g.
>
> echo class_exists('Foo') ? 'Foo.php found' : 'Foo.php not found';
>
> Some will simply recommend checking to see if the file Foo.php exists
> before including it, but thanks to the include_paths setting, that's
> easier said than done!
>
Toby,
@include 'Foo.php';
should do the same thing, but I haven't tried it. Rather, I use
require_once on all my files; there's a reason I include them - because
I need them.
But you're right - include paths make things very difficult to determine
if a file exists or not. You could parse the entire include path, but
it's a lot of unnecessary work.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|