Php static variables

Source: Internet
Author: User
Tags classe
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$classesAfter 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;$classesAll operations are performed on this address (0x123;

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.