Cat
Cat

Reputation: 7322

How to load a PEAR package

I've just installed a PEAR package (Event_Dispatcher) and I can't use the classes in that package. When I run the command pear list I see the new package, however I see that the classes in the package are saved in /usr/lib/php (I have a Mac).

Is there a loading part after installing a PEAR package? How exactly do I move the files to the right place? Can I simply cut and paste the folder to the pear root folder?

Thanks!

Upvotes: 4

Views: 2405

Answers (2)

Sam Day
Sam Day

Reputation: 1719

When PEAR is installed it usually automagically configures your php.ini to add the PEAR library path to the php.ini. Then, for each package, the authors will usually provide a file that will load the library for you which sits in the root of this PEAR lib directory.

For example, a PEAR package MDB2 has a load of different classes located under /MDB2, but there's also a PHP script at /MDB2.php, so all you need to do from your PHP code is this:

require_once("MDB2.php").

You'll obviously need to keep track of what you have installed on your local dev machine and make sure it's installed on the production server(s) too.

Upvotes: 1

Marc B
Marc B

Reputation: 360912

Most PEAR packages have to be included via the usual include() and require() functions. They're not precompiled binaries, like (say) the MySQL driver (mysql.so/mysql.dll) are. As long as /usr/lib/php is in your include_path, PHP should be able to load up the package automatically when you do include('nameofpackage.php').

Upvotes: 2

Related Questions