|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-11-17 06:24 UTC] snowy at corporatezoo dot com
Description:
------------
Behaviour of require/include different to < 5.2.0.
I'm not sure if this is by design, couldn't find any reference to it in release notes. Basically, the search order of an include seems to always start with ./ instead of in the order of get_include_path(). This is problematic, esp in the case of using autoload, where a filename eg in ./index.php might be the same as ../classes/Index.php, ./index.php gets autoloaded instead of ../classes/Index.php
Reproduce code:
---------------
//index.php
set_include_path('../classes;.');
function __autoload($class)
{
if (!require_once($class.'.php')) {
error_log('Error: Autoload class: '.$class.' not found!');
}
}
$index = new Index();
//../classes/Index.php
class Index
{
//blah
}
Expected result:
----------------
In 5.1.6, it works ok, loads Index.php
Actual result:
--------------
in 5.2.0,
Fatal error: Class 'Index' not found in c:\docroot\index.php
I suspect it's looking for a class in index.php (Which is the currently executed script).
Is this an architectural change? Or is this a bug?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
actually I am using full paths, I'm doing a: define('SITEROOT_DIR','/web/myproject'); define('FRAMEWORK_DIR','/web/framework'); define('SITECLASS_DIR',SITEROOT_DIR.'/_application'); set_include_path(SITECLASS_DIR.';'.FRAMEWORK_DIR.';'.get_include_path()); and /web/myproject/docroot is the docroot (I've always been using this kind of naming with "/" for windows since 4.0.x in case I need compat) It's almost as if it found index.php in the current namespace, and decides it doesn't need to go to include_path to look for one? just guessing...Test case: Create a file called test.php with the following: <?php set_include_path(dirname(__FILE__).'/lib/'); echo(get_include_path()."\n"); require_once('test.php'); ?> and create a subdirectory called lib, containing a file called test.php with the following contents: Included Test from lib/ Results with php 4 (PHP 4.4.4 (cli) (built: Nov 1 2006 18:10:56) -- osx 10.4.x: /Users/jsnell/delete/php5/testcase/lib/ Included Test from lib/ Results with PHP 5.1.4 (PHP 5.1.4 (cli) (built: Jan 25 2007 11:50:25) ): php5 test.php /Users/jsnell/delete/php5/testcase/lib/ Included Test from lib/ Results with PHP CVS (anon checked out on February 2nd): ../sapi/cli/php test.php /Users/jsnell/delete/php5/testcase/ -- I believe the original submission is wrong, by changing require_once() to require(), the file from lib/ is being loaded.hi tried the windows snap, also just tried 5.2.1 and same problem. I'll just confirm with jsnell's observation that it is indeed require_once that is throwing that exception. require seems to work fine. ie function __autoload($class) { require_once($class . '.php'); } breaks whilst function __autoload($class) { require($class . '.php'); } workstried this on 5.2.1 on OSX as well and it also fails. Another thing: if my file is in /project/docroot/file.php even if I do a: require_once('/project/classes/File.php'); it still fails. Notice that it's (1) case insensitive, (2) the actual full path is given in require_once. I thought it may have been caching the full path, but looks like it's only looking if '[F|f]ile.php' (the file name) has been loaded. Ie, even set_include_path('/project'); require_once('classes/file.php'); // give a path name to avoid namespace clash doesn't work. Is this going to be fixed? Or should we go and change all our include_once/require_once if we want to upgrade to > 5.1.6? thx