Section 12 - Automatic Loading of Class - Classes and Objects in PHP5 [12]

zhaozj2021-02-16  56

Section 12 - Automatic Loading of Class - Classes and Objects in PHP5 [12]

Author: Leon Atkinson translation: Haohappy Source: Beyond the PHP / * ------------------------------------ ------------------------------------------ | = This article is HaohappY << CORE PHP Programming >> | = Classes and Objects Chapter Note | = Translate Main Personal Experience | = To avoid unnecessary troubles, please do not reprint, thank you | = Welcome criticism, hope and all PHP enthusiasts progress together! ----------------------------------------- ---------------------------------- * / 12 - Automatic loading When you try to use an undefined class, PHP will report a fatal error. Solution is to add a class, you can include a file with include. After all, you know which class to use. However, PHP provides the automatic load function of the class. This saves programming time. When you try to use a PHP unmelated class, it will look for __autoload global functions. If this function is present, PHP will use a parameter to call it, parameter is the name of the class. Example 6.15 illustrates how __autoload is used. It assumes that each file is corresponding to a class in the current directory. When the script tries to generate a class user instance, PHP will execute __autoload. Script assumes that Class_User.php defines a User class .. Regardless of the call or lowercase, PHP will return to the name. LLISTING 6.15 Class AutoLoading name =" leon "; $ u-> printname ();?>>>

转载请注明原文地址:https://www.9cbs.com/read-21563.html

New Post(0)