PHP automatic load class settings include directory whatever new is not wrong _php tutorial

Source: Internet
Author: User
get_include_path-getting the current include_path configuration options

String Get_include_path (void)


set_include_path-Setting include_path configuration options
String Set_include_path (String $new _include_path)


First Set_include_path This function, is in the script dynamically to php.ini in the include_path to modify.
And this include_path, it can be defined for the following include and require path range, or is predefined.
It's like:
If we do not set this value, we may need to write some full paths:


[PHP]
Include ("123/test1.php");
Include ("123/test2.php");
Include ("123/test3.php");
Require ("123/test4.php");
Require ("123/test5.php");
?>

Include ("123/test1.php");
Include ("123/test2.php");
Include ("123/test3.php");
Require ("123/test4.php");
Require ("123/test5.php");
?>

To introduce many external files, but if we set the Set_include_path ("123/"), we can use the following code instead.
[PHP]
!--? php
set_include_path ("123/");
include ("test1.php");
include ("test2.php");
include ("test3.php");
require ("test4.php");
require ("test5.php");
?>

!--? php
set_include_path ("123/");
include ("test1.php");
include ("test2.php");
include ("test3.php");
require ("test4.php");
require ("test5.php");
?> So this function can not only define a folder, we can define a lot of folders. As shown below, I'm going to write an initialization function:
[PHP]
Function Initialize ()

Set_include_path (Get_include_path (). Path_separator. "Core/");
Set_include_path (Get_include_path (). Path_separator. "app/");
Set_include_path (Get_include_path (). Path_separator. "admin/");
Set_include_path (Get_include_path (). Path_separator. "lib/");
Set_include_path (Get_include_path (). Path_separator. "include/");
Set_include_path (Get_include_path (). Path_separator. " data/");
Set_include_path (Get_include_path (). Path_separator. " cache/");

Function Initialize ()
{
Set_include_path (Get_include_path (). Path_separator. "Core/");
Set_include_path (Get_include_path (). Path_separator. "app/");
Set_include_path (Get_include_path (). Path_separator. "admin/");
Set_include_path (Get_include_path (). Path_separator. "lib/");
Set_include_path (Get_include_path (). Path_separator. "include/");
Set_include_path (Get_include_path (). Path_separator. " data/");
Set_include_path (Get_include_path (). Path_separator. " cache/");
So its path is:

.; c:\php5\pear;core/;app/;admin/;lib/;include/;d ata/;cache/


Here's an example.

[PHP]
$include _path=get_include_path (); Original Base Directory
$include _path.=path_separator. " include/";
$include _path.=path_separator. " classs/";
$include _path.=path_separator. " Libs/";
echo $include _path;
Set up all directories where the include contains files
Set_include_path ($include _path);

function __autoload ($className)
{
echo ' class '. $className;
Include Strtolower ($className). ". Class.php ";
}
$Smarty = new Smarty;
?>

$include _path=get_include_path (); Original Base Directory
$include _path.=path_separator. " include/";
$include _path.=path_separator. " classs/";
$include _path.=path_separator. " Libs/";
echo $include _path;
Set up all directories where the include contains files
Set_include_path ($include _path);

function __autoload ($className)
{
echo ' class '. $className;
Include Strtolower ($className). ". Class.php ";
}
$Smarty = new Smarty;
?>


When multiple directories are specified as Include_path, and the required files are present in files with the same name in each of these directories, PHP chooses to use the files in the pre-ranked directory when the Include_path is set.

So you can go straight to new pull!!

http://www.bkjia.com/PHPjc/477451.html www.bkjia.com true http://www.bkjia.com/PHPjc/477451.html techarticle Get_include_path Gets the current include_path configuration option string Get_include_path (void) Set_include_path Settings include_path configuration options string Set_include_path (String $new _ ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.