简体   繁体   English

默认情况下,PHP / Apache是​​否会寻找一个include文件夹?

[英]Does PHP/Apache look for an includes folder by default?

I have recently discovered set_include_path() and have found that the path that is returned is the path to my includes directory. 我最近发现了set_include_path(),并且发现返回的路径是我的include目录的路径。

Does PHP automatically look for an includes directory and update the include_path to this? PHP是否会自动寻找一个include目录并更新include_path到这个目录?

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. 我还注意到,当在类本身之外设置时,用set_include_path设置的一些路径在类方法内不可用。

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! 预先感谢您的所有建议!

this (any "automated" lookup of an includes directory) would be set in a php.ini file. 这个(包含目录的任何“自动”查找)将在php.ini文件中设置。 make a test page called test.php containing: 制作一个名为test.php的测试页面,其中包含:

<?php phpinfo(); ?>

point your browser to test.php and look for this variable: 将您的浏览器指向test.php并查找以下变量:

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

you can also find which php.ini file is being used: 您还可以找到正在使用的php.ini文件:

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: 如果您是从命令行运行而不是通过浏览器运行,则可以使用以下命令检查ini文件:

php -r "phpinfo();" | less

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM