Add a path to the PHP include path

I recently wanted to add a Zend library to a project without adding the entire framework.

I found that internally, the Zend application requires the Library path to be in the include, as it uses relative includes. So, easy to fix without editing the actual pages. I just needed to add the folder they were in, to the PHP include path.

function add_path_to_include ($path)
    //get the existing paths using the PATH_SEPERATOR constant
    $paths = explode(PATH_SEPARATOR, get_include_path());

    //if the new path isn't already there
    if (array_search($path, $paths) === false) {

        //add it on
        array_push($paths, $path);

    //add them all back on
    set_include_path(implode(PATH_SEPARATOR, $paths));

Jobs a goodun…

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.