Reputation: 10893
Please enlighten me on this one. I tried editing the php.ini file, on the part where it says include_path:
include_path = ".;C:\php_includes\home_made"
After that I uncommented it,save it and restarted all services from wamp tray icon.
I have a bunch of home made classes on that folder. I'm imagining that I could just do something like this on every php file that I make. And I'll be able to use the functions in those classes:
$strings = new strings();
echo $strings->clean('bla$#@D232)*/');
But I was wrong since it returned this error:
Fatal error: Class 'strings' not found in C:\wamp\www\dw_fs\phpinfo.php on line 1
What benefit did I actually get from including a path in php.ini. How do I use it? Please enlighten me.
Upvotes: 1
Views: 743
Reputation: 6406
You still need to include your string
class. Just calling it won't work - but if the file is in the include path then you don't actually need to specify the full path to the file.
If you want to get PHP to auto include the files for you, read up on Autoloading Classes
Upvotes: 2
Reputation: 145512
The include_path just allows to include
files without full path:
include("strings.php"); // instead of "c:/includes/strings.php"
What you wanted to use in your example is an autoloader
in addition to setting the include_path
:
spl_autoload_extensions('.php');
spl_autoload_register("spl_autoload");
Then you can instantiate the strings class without manually including the required class file.
Upvotes: 1
Reputation: 50029
It allows you to include files using include() and require() without having to specify the full path.
From the manual : http://www.php.net/manual/en/ini.core.php#ini.include-path
Specifies a list of directories where the require(), include(), fopen(), file(), readfile() and file_get_contents() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows.
PHP considers each entry in the include path separately when looking for files to include. It will check the first path, and if it doesn't find it, check the next path, until it either locates the included file or returns with a warning or an error. You may modify or set your include path at runtime using set_include_path().
Upvotes: 2