Including files from include path not working as expected

拥有回忆 提交于 2019-12-11 21:10:40

问题


When I run this code in a php file:

get_include_path();

I get this result:

.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear

So shouldn't all files from either of these 2 directories be automatically included in all my php files? Because when I put a file with a class in 1 of them and try using it in my php file, it says

Fatal error: Class 'FirePHP' not found in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 4


回答1:


You misunderstood the include_path. It won't include automatically all the files in there.

The include_path is a list of paths from where you can include with an relative path.

So, if you write include 'FirePHP.php'; then the file, if it exists in one of these paths, . (this directory), /Applications/XAMPP/xamppfiles/lib/php or /Applications/XAMPP/xamppfiles/lib/php/pear, will be included.




回答2:


You can include a file using include_once or require_once.

eg.

include_once '/path/to/your/classfile'


来源:https://stackoverflow.com/questions/17003614/including-files-from-include-path-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!