Php class automatic loading method. Php class automatic loading method before PHP5, if each PHP framework needs to implement automatic loading of classes, it generally implements a traversal directory according to certain conventions, automatically load all php-compliant methods
Before PHP5, if PHP frameworks need to implement automatic class loading, they generally implement a traversal directory according to certain conventions and automatically load all classes or functions that comply with the agreed rules. Of course, PHP5's previous object-oriented support was not very good, and classes were not frequently used. Let's discuss it in detail.
Php automatic loading method
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 |
Class inload
{
/**
* The class is automatically loaded and does not need to be called by the developer.
*
* @ Param string $ class file
*/
Private function autoload ($ class)
{
If (empty ($ class ))
{
Throw new QException ('loading file does not exist'. $ class );
}
Else
{
Require _ SPRING _. '/_ Core/SpringMap. php'; // framework map
If (! File_exists ($ source [$ class] ['file'])
{
Throw new QException ('loading file does not exist'. $ class );
}
Require $ source [$ class] ['file'];
}
}
/**
* Register or unregister an automatic class loading method
*
* For more information about this method, see Zend Framework.
*
* @ Param string $ class: class that provides automatic loading service
* @ Param boolean $ enabled or disabled this service
*/
Private function registerAutoload ($ class = 'interpreter', $ enabled = true)
{
If (! Function_exists ('SPL _ autoload_register '))
{
Throw new QException ('SPL _ autoload does not have this PHP installation ');
}
If ($ enabled = true)
{
Spl_autoload_register (array ($ class, 'autoload '));
}
Else
{
Spl_autoload_unregister (array ($ class, 'autoload '));
}
}
/**
* Destructor
*/
Public function _ destruct ()
{
Self: registerAutoload ('interpreter', false );
}
|
The above is all the content of this article. I hope you will like it.
Http://www.bkjia.com/PHPjc/1010440.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1010440.htmlTechArticlephp class automatic loading method before PHP5, each PHP framework to achieve automatic loading of classes, generally according to a certain agreement to achieve a traversal Directory, automatically load all the compliance...