Hi I am Totally Lost

All Forgive me!!!

But I am a JAVA developer.  Used IntellIJ FOREVER.  Learning PHP using PHP Storm.  But including external PHP libs is making me crazy.
I am trying to use some PEAR PHP SDO classes to read a schema and then enter data.

How do I use PEAR Libs?

How do I load it?  In some code it seems you can extend base PHP with it.  ie not using INCLUDE... ?

How does PHPStorm includes work?

When I build a project and need external PHP class libs, I copy them into my new project directory.
Talk about version NOT IN CONTROL!

Using WAMP and MAMP for my PHP installs (Windows and MAC).

Got lots of stuff working, but the PHP build out just is not cutting it!  I NEED JAR files :)

I have downloaded PEAR installers.  Cannot find a PECL exe?

Not looking for hand holding, any links?



Okay, so you are having several issues here.  I'm going to try and tackled them one at a time.  Forgive me if I misunderstand something.  Just stay calm and carry on. =)

First, the way PHP handles includes and the way PHP Storm handles includes are two different things.  That's fine.  That's because different environments (dev, test, staging, production) might handle things differently (one might cache, one might not, etc).  Anyways, the point is, handling one doesn't automatically handle the other.

Anyways, any library you want to use needs to be found on the include path in PHP.  Now, PHPStorm will let you set the include_path you'd like to use in the IDE.  Below the project, right click on the External Libraries entity, and choose the Configure PHP Includes option.  You'll get a window up.  From there, you want to add in the Include Paths you want to include.  This is most likely the include patch to where PEAR is installed on your system (which you can get via the command line by running 'pear config-get php_dir').

This will tell PHPStorm to look in that directory for library files.  You can include as many directories as you want, but keep in mind, it will look recursively into whatever directory you set.  That's why setting all of PEAR is probably best, as it shows you all the libraries you've installed via PEAR.

Keep in mind that PHP isn't compiled.  There really is no "build" phase.  The files are interpreted at run time.

Anyways, with that in mind, you need to ensure that PHP also includes these directories in it's include path.  This can be found by viewing phpinfo() output, get_include_path() output, or, more easily from the command line: php -i | grep include_path.  You are looking for a line like this:

include_path => .:/usr/local/Cellar/php54/5.4.3/lib/php => .:/usr/local/Cellar/php54/5.4.3/lib/php

This can be set via php.ini

You can also set this during run time with the set_include_path() function (just make sure to get_include_path() as well).

With that in place, when you want to use a package, you can include it in your file like so:

require_once 'PEAR/Package.php';

And PHP will prepend each path in include path to the front of that, in order, until it finds a match.  As an aside, this means you can easily override packages with your own simply by putting them in an include path that gets looked at first.

Anyways, you can also automate all this so you don't have to use require_once at the top of your file.  You can set it so whenever you are in your PHP code, if you type

$package = new Package();

PHP will automatically go out and look for the Package class.  This is called autoload'ing, and more information can be found here:


There is unofficial standard for PHP autoloading, called PSR-0 (there is a PSR-1 and PSR-2 as well), and this can be found here;


That includes an autoload function that you can use, and it will basically work for all libraries that conform to PSR-0 standards (which most of the important ones do).

Anyways, I hope this gets started off on the right track.

Oh, and while I'm not on windows, the documentation covers installing PECL on windows here: http://www.php.net/manual/en/install.pecl.windows.php

Please sign in to leave a comment.