Today I want to learn about phpcms, And then I read the source code, but I have some questions when I look at the _ load_class method. {Code ...} static $ classesarray (); If the static attribute is not added, an empty array is declared. is static... added... today I want to learn about phpcms, And then I read the source code, but I have some questions when I look at the _ load_class method.
/*** Load class file function * @ param string $ classname class name * @ param string $ path Extension address * @ param intger $ initialize whether to initialize */private static function _ load_class ($ classname, $ path = '', $ initialize = 1) {static $ classes = array (); if (empty ($ path) $ path = 'libs '. DIRECTORY_SEPARATOR. 'classe'; $ key = md5 ($ path. $ classname); if (isset ($ classes [$ key]) {if (! Empty ($ classes [$ key]) {return $ classes [$ key];} else {return true ;}} if (file_exists (PC_PATH. $ path. DIRECTORY_SEPARATOR. $ classname. '. class. php ') {include PC_PATH. $ path. DIRECTORY_SEPARATOR. $ classname. '. class. php '; $ name = $ classname; if ($ my_path = self: my_path (PC_PATH. $ path. DIRECTORY_SEPARATOR. $ classname. '. class. php ') {include $ my_path; $ name = 'my _'. $ classname;} if ($ initialize) {$ classes [$ key] = new $ name;} else {$ classes [$ key] = true ;} return $ classes [$ key] ;}else {return false ;}}
Static $ classes = array (); If the static attribute is not added, an empty array is declared, after the first call, is the value of this array actually the value after the last change? I didn't understand how he saved the value to the $ classes array and solved it. Or someone familiar with phpcms can explain how to call classes and functions. Thank you!
Reply content:
Today I want to learn about phpcms, And then I read the source code, but I have some questions when I look at the _ load_class method.
/*** Load class file function * @ param string $ classname class name * @ param string $ path Extension address * @ param intger $ initialize whether to initialize */private static function _ load_class ($ classname, $ path = '', $ initialize = 1) {static $ classes = array (); if (empty ($ path) $ path = 'libs '. DIRECTORY_SEPARATOR. 'classe'; $ key = md5 ($ path. $ classname); if (isset ($ classes [$ key]) {if (! Empty ($ classes [$ key]) {return $ classes [$ key];} else {return true ;}} if (file_exists (PC_PATH. $ path. DIRECTORY_SEPARATOR. $ classname. '. class. php ') {include PC_PATH. $ path. DIRECTORY_SEPARATOR. $ classname. '. class. php '; $ name = $ classname; if ($ my_path = self: my_path (PC_PATH. $ path. DIRECTORY_SEPARATOR. $ classname. '. class. php ') {include $ my_path; $ name = 'my _'. $ classname;} if ($ initialize) {$ classes [$ key] = new $ name;} else {$ classes [$ key] = true ;} return $ classes [$ key] ;}else {return false ;}}
Static $ classes = array (); If the static attribute is not added, an empty array is declared, after the first call, is the value of this array actually the value after the last change? I didn't understand how he saved the value to the $ classes array and solved it. Or someone familiar with phpcms can explain how to call classes and functions. Thank you!
The first call,static $classes = array()
Initialization$classes
After static variables, there is an address in the memory (assuming 0x123), as long as the php script is not terminated,Call again next timestatic $classes = array()
It will not be initialized again$classes
;$classes
All operations are performed on this address (0x123;