include_path seems to be ignored when including PHP files

HappyDog

New member
Hi there,

Further to my previous comment, I’m also finding an issue with the use of the include_path variable in the include_once() function. I don’t think this is directly related to the other issue I reported, but perhaps it is.

The problem I am having is that I am getting the following error when trying to include the PEAR DB module:
Code:
Warning: include_once(DB.php): failed to open stream: No such file or directory
The application has as a local copy of the PEAR libraries, so these do not need to be installed separately, and it sets the include_path setting appropriately to point to them. If I print out the value of the include_path setting just prior to calling include_once() then it seems to be pointing to the correct location:

.;X:\framework\libraries\pear

However it looks like the path isn’t being used. It works fine when running in normal PHP.

Thoughts? Bug?

– HappyDog
 
Yes - the project sets the include_path (or rather, adds to it) using ini_set(). The change seems to have an effect as the right thing is returned by ini_get() afterwards, so it seems like the setting is being set correctly.

– HappyDog
 
…or do you mean do I set in in the php.ini that goes into the project. In which case, no. Is that necessary? Does ini_set() not work in ExeOutput?

– HappyDog
 
There is no reason why ini_set() wouldn’t work. Could you please post the PHP code with the ini_set() command that sets the path? Have you tried to set relative or full paths?
 
Hi there,

The issue is in our framework, so not easy to post the code (would require sending the whole framework).

I will see if I can create a small test-case instead.

Will let you know how I get on.
Have you tried to set relative or full paths?
The paths are being set as per my original post (using ini_set()) and are returned correctly by ini_get(). The path where the file should be loaded from is the absolute path to pear, but the path includes the relative cwd path: “.”

– HappyDog
 
Last edited:
I think the issue is in the ExeOutput.
I have tested follow example:
Code:
set_include_path(realpath('classes') . PATH_SEPARATOR . get_include_path());
spl_autoload_register(function($className) {
	$classFile = $className . '.php';
	$file = stream_resolve_include_path($classFile);
	if($file) {
		require_once $file;
		print 'class ' . $className . ' loaded with include path<br>';
	}
});

$paths = explode(PATH_SEPARATOR, get_include_path());
spl_autoload_register(function($className) use($paths) {
	foreach($paths as $path) {
		$classFile = $path . DIRECTORY_SEPARATOR . $className . '.php';
		if(file_exists($classFile) && is_readable($classFile)) {
			require_once $classFile;
			print 'class ' . $className . ' loaded without include path<br>';
		} 
	}
});

$class = new TestClass();
The first run in the compiled application says:
class TestClass loaded without include path

by pressing the reload button or other action, the application says:
class TestClass loaded with include path

I think ExeOutput ignored by the first run the include path
 
Back
Top