473,789 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to see if a PEAR package exists?

I want to know if some particular PEAR package (for example, DB,
XML_RPC) exists. How can I do that in PHP?

Thanks,
Dec 7 '07 #1
6 2324
..oO(AnrDaemon)
>Greetings, Ming.
In reply to Your message dated Friday, December 7, 2007, 22:08:19,
>I want to know if some particular PEAR package (for example, DB,
XML_RPC) exists. How can I do that in PHP?

Try to include them and catch an exception. (As fast and dirty way)
Not that fast, since you also have to write your own error handler to
throw the exception.

Micha
Dec 8 '07 #2
Jerry Stuckle wrote:
including a file which does not exist will not throw an exception.
My general method is:

$old_error_repo rting = error_reporting (E_ERROR);
include 'Foo.php';
error_reporting ($old_error_rep orting);

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('F oo') ? '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 A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 21:34.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 8 '07 #3
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_repo rting = error_reporting (E_ERROR);
include 'Foo.php';
error_reporting ($old_error_rep orting);

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('F oo') ? '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.
js*******@attgl obal.net
=============== ===

Dec 8 '07 #4
On Dec 8, 7:44 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
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_repo rting = error_reporting (E_ERROR);
include 'Foo.php';
error_reporting ($old_error_rep orting);
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('F oo') ? '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.
jstuck...@attgl obal.net
=============== ===
@include "Foo.php";
if (!class_exists( "Foo")) {
// Code to handle missing PEAR file.
}
Dec 9 '07 #5
allain wrote:
On Dec 8, 7:44 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>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_repo rting = error_reporting (E_ERROR);
include 'Foo.php';
error_reporting ($old_error_rep orting);
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('F oo') ? '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.
jstuck...@attg lobal.net
============== ====

@include "Foo.php";
if (!class_exists( "Foo")) {
// Code to handle missing PEAR file.
}
Which assumes "Foo.php" exists only once in the include path, and
defines the class "Foo".

Also, the '@' in this case hides an important error message; I include
the file because I *need* the file. If it's not there, my code is useless.

Your code is completely unnecessary and causes additional overhead in a
properly designed system.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 10 '07 #6
Jerry Stuckle wrote:
That's where we differ. I don't use optional classes. But that's not
to say there is anything wrong with your way - it's perfectly fine. Just
my personal preference.
Nor do I usually.

But for my Blog/CMS, I like to be able to take advantage of third-party
libraries that might be installed on the server, but without making my
code completely dependent on them. So the code checks to see if they're
available, and if so uses them. If not, then perhaps you miss out on a
cute little feature, but it's no big deal.

Another way to do this is to have some configuration file somewhere with:

$blah_module_is _installed = FALSE;

and later:

if ($blah_module_i s_installed)
{
include "blah.php";
blah();
}

but this requires the site administrator to manually enable the blah
extension. Perhaps I have been using Macs too much, but I think that
"detect if cool feature X is available, and if so use it without a fuss"
is a good philosophy.

Of course, there are some PEAR libraries that my CMS absolutely requires,
and in those cases it would of course allow for the error to be raised
when the included file is not found!

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 3 days, 23:42.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 11 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1512
by: Analysis&Solutions | last post by:
Greetings: Crack open the beer, PEAR DB 1.6.0 is here! (Hey, I'm a bit giddy with excitement that my intense work during the past seven weeks has come to fruition.) For those unfamiliar with PEAR DB, it's a package of PHP classes that provide an object oriented API with common methods of accessing thirteen of PHP's database driver extensions: dBase, FrontBase, InterBase, Informix, mSQL, MS SQL Server,
3
7246
by: junkmail | last post by:
on a win 2k server apparantly it is saying i dont have it. or it cant find it. im using mySQL 4.1 php 4.3.x apache 3.0.53 im new to php and am doing some tutorials, but when i run the sripts it tells mea it can not run pear/soap, because it can not be found.the book im learning form does not tell me how to install or configure this extension. so now im looking for help.
1
2048
by: DJ Majestik | last post by:
OK, I am new to the whole PEAR/Smarty templating thing. I am trying to setup my directory structure correctly. If someone could weigh in and see if I have this setup "right", I would appreciate it. Directory structure: pear/ db/ db/ DB/ doc/
2
3053
by: David | last post by:
I have a book which had code that includes the line: require 'DB.php'; I know that this is from the PEAR code modules, but when I downloaded them and unpacked the directory, they "DB.php" module does not exist. Is this out of date or do I need to go somewhere else to get this extra module? Thanks
1
7842
by: CSTechie | last post by:
I've been battling to install PEAR on Windows XP now for too long. I am not sure what I need to do. When I run go-pear.php from the command line, I get the error message as shown at the end. I included everything in case there is something there that's helpful. I'm trying to install PEAR so that I can use PHPUnit. Thanks for the help!!!!
2
2460
by: jhalaseh | last post by:
Hello, Was wondering if anyone could help me out with a bit of wierd prob. I have pear installed in a UNIX box, with PHP 5.1.2. I'm trying to install some packages by running pear install package.tgz, but always end up with something like .... pear/XML_Parser requires package "pear/PEAR" No valid packages found install failed
1
1659
by: Paul | last post by:
I just installed php 4.4 with apache 2.0 on WIN XP. All is working so far. From: the prompt, I type: go-pear and here's what I get: Loading zlib: ok Using local package: PEAR-stable......ok Using local package: Archive_Tar-stable....ok Using local package: Console_Getopt-stable....ok Using local package: XML_RPC-stable....ok Bootstrapping: PEAR...................(remote) <!DOCTYPE html PUBLIC
3
9298
by: Anthony Smith | last post by:
I always get this message. No matter what package $ pear install Date PHP Warning: Module 'oci8' already loaded in Unknown on line 0 No releases available for package "pear.php.net/Date" Cannot initialize 'Date', invalid or missing package file Package "Date" is not valid install failed
0
3550
snowdonkey
by: snowdonkey | last post by:
I'm trying to use the Mail package from PEAR in a script that sends an e-mail over SMTP. The problem is that the Mail class in Mail.php provided by the package isn't found by the script. I'm using: require_once "Mail.php"; and I get the messages: I've made sure that include_path in my php.ini file is directed to my PEAR folder containing pear.bat. It looks like this (I've tried different capitalizations): ; Windows:...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.