开发者

PHP include_once not working for file in parent directory

开发者 https://www.devze.com 2022-12-19 01:40 出处:网络
I just started working on a site that has been passed down to me that isn\'t working. I\'ve found that there\'s a problem when in /admin/index.php it tries to instantiate an instance of /classes/admin

I just started working on a site that has been passed down to me that isn't working. I've found that there's a problem when in /admin/index.php it tries to instantiate an instance of /classes/admin.php. However, if I copy /admin/index.php to /admin-index.php, it can instantiate the class just fine. Also, if I move /classes/admin.php into /admin/classes/admin.php, I can also instantiate it just fine. There is at least one other class that I've noticed this with.

I've also noticed that this isn't a problem on my local development machine. It's only an issue on the server.

You can find info about the server at http://charlesekublyfoundation.org/admin/phpinfo.php. My development machine is a WinXP machine running Apache 2.2 and PHP 5.2.11 (Apache/2.2.14 (Win32) PHP/5.2.11 ).

Has anyone seen anything like this? It seems odd. I'm fairly new to PHP development (primarily .NET developer), so I'm not sure what would cause this. I'm not sure if it's a difference in PHP or Apache or something else.

EDIT I should note that my server is running on some brand of Linux while by dev mach开发者_如何学Goine is Windows. I'm having a feeling that has something to do with this after looking into include_paths.


There's a couple of things I can think of that might have a hand in this problem.

The most likely one I think from your description is that the developer was relying on PHP's include_path setting. This setting works with the require() and include() commands to tell them where to look for the requested file in the event that a hard path is not provided. If the code is using relative paths, and the include_path settings are different, it could be a problem. Generally the include_path will contain the "current directory" (ie, .) as part of the path, and includes are done using that as a base.

Another possibility is that the application is utilizing autoloading, and somehow this isn't translating properly to production. I'd do a quick search through the application and see if there's an __autoload() function specified, or spl_autoload_register() is used. If they are, perhaps the auto-loading function is making directory assumptions that are only true on the development machine?


You should examine the include paths to see why it's not working properly. The include path information will be located in your PHP configuration file (typically php.ini) as well as in the application itself. In the application you can try using the function get_include_path and print out what it returns.

0

精彩评论

暂无评论...
验证码 换一张
取 消