You are here: Re: How to see if a PEAR package exists? « PHP Programming Language « IT news, forums, messages
Re: How to see if a PEAR package exists?

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
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация