-1

I have recently discovered set_include_path() and have found that the path that is returned is the path to my includes directory.

Does PHP automatically look for an includes directory and update the include_path to this?

I have also noticed that the few paths that I set with set_include_path are not available inside a Class Method when set outside of the Class itself.

Why is this?

$include_root = $_SERVER['DOCUMENT_ROOT'] . '/path/to/includes/';
$include_paths = get_include_path() . PATH_SEPARATOR .
                 $include_root . PATH_SEPARATOR .
                 $include_root . 'classes/' . PATH_SEPARATOR;

set_include_path( $include_paths );

Thanks for all your advice in advance!

hungerstar
  • 21,206
  • 6
  • 50
  • 59
  • Can you clarify what you mean by setting the include path "outside of the Class"? Is this in a separate file from the class definition? In what order are things initialised? Also, could there be another call to `set_include_path` (or `ini_set('include_path', ...)`) running in between these parts of the code? – IMSoP Aug 18 '12 at 16:16

1 Answers1

3

this (any "automated" lookup of an includes directory) would be set in a php.ini file. make a test page called test.php containing:

<?php phpinfo(); ?>

point your browser to test.php and look for this variable:

include_path    .:/usr/share/php:/usr/share/pear

you can also find which php.ini file is being used:

Loaded Configuration File   /etc/php5/apache2/php.ini

I don't have an answer for the class methods question.

If you're running from the command line and not through the browser, you can check the ini file using:

php -r "phpinfo();" | less
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • the value I see via phpinfo(); is: .;C:\xampp\php\PEAR I am curious as to why this is not the value returned. – hungerstar Sep 20 '11 at 04:21
  • hmm, me too! what value *is* returned? – jcomeau_ictx Sep 20 '11 at 04:25
  • right now i'm on development so it's: C:/xampp/htdocs/sitename/includes/ if called within my class method. The result is the same with or without setting the include paths with set_include_path() outside of the class itself. I know if I set the paths within the class constructor all works fine. I am curious as to why. – hungerstar Sep 20 '11 at 05:12
  • what does "on development" mean? you're not running it through Apache but rather through the command line? see updated answer. – jcomeau_ictx Sep 20 '11 at 05:22
  • sorry, just meant that I'm developing locally and not in a production environment for this. It probably doesn't affect the issue. I use Xampp to develop my sites locally before pushing them live. – hungerstar Sep 20 '11 at 05:28