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.

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.