Jump to content

how set_include_path and implode and PATH_SEPARATOR work together?


johnmerlino

Recommended Posts

Hey all,

 

It's easy to look at documentation and see what each of these functions and that super global do individually. But I'm not sure how the three are working together here:

 

define('APPLICATION_PATH', realpath('../'));

$paths = array(
APPLICATION_PATH,
get_include_path()
);
set_include_path(implode(PATH_SEPARATOR, $paths));

 

Thanks for response.

 

Link to comment
Share on other sites

In that simple example there is no need for all that code. The same thing could be achieved using....

 

define('APPLICATION_PATH', realpath('../'));
set_include_path(get_include_path() . PATH_SEPARATOR . '../');

 

Now, the thing is, if you wanted to add more than one simple path you would use the code you posted.

 

You know that implode takes an array and turns it into a string using a specified char as a separator. So....

 

$a = array('a', 'b', 'c');
echo implode('|', $a);

 

Produces a|b|c

 

Now, you know that an include path looks something like (on Linux)

 

.;/usr/share/php;/usr/share/Zend/lib;/usr/share/www/lib

 

So, if that is our current include path, and we take the code you posted above (and assume that realpath('../') produces /home/thorpe/var/www). Our include path would now be...

 

.;/usr/share/php;/usr/share/Zend/lib;/usr/share/www/lib;/home/thorpe/var/www

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.