包含来自包含路径的文件未按预期工作 [英] Including files from include path not working as expected
问题描述
当我在 php 文件中运行此代码时:
When I run this code in a php file:
get_include_path();
我得到了这个结果:
.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear
.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear
那么这两个目录中的所有文件不应该自动包含在我的所有 php 文件中吗?因为当我将一个带有类的文件放在其中一个文件中并尝试在我的 php 文件中使用它时,它说
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
致命错误:在第 4 行的/Applications/XAMPP/xamppfiles/htdocs/index.php 中找不到FirePHP"类
Fatal error: Class 'FirePHP' not found in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 4
推荐答案
您误解了 include_path
.它不会自动包含其中的所有文件.
You misunderstood the include_path
. It won't include automatically all the files in there.
include_path
是一个路径列表,您可以从中包含相对路径.
The include_path
is a list of paths from where you can include with an relative path.
因此,如果您编写 include 'FirePHP.php';
则该文件,如果它存在于这些路径之一中,.
(此目录),/Applications/XAMPP/xamppfiles/lib/php
或 /Applications/XAMPP/xamppfiles/lib/php/pear
,将包括在内.
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.
这篇关于包含来自包含路径的文件未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!