问题
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