Home >Backend Development >PHP Tutorial >Section 12--Automatic loading of classes--ClassesandObjectsinPHP512_PHP tutorial

Section 12--Automatic loading of classes--ClassesandObjectsinPHP512_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:24:08809browse

| = This article is read by Haohappy > | = Notes from the Chapter Classes and Objects | = Translation + personal experience | = Please do not reprint to avoid unnecessary trouble that may occur, thank you | = Welcome to criticize and correct me, Hope to make progress together with all PHP enthusiasts! +------------------------------------------------ ---------------------------------------+ */ Section 12--Class Autoloading PHP will report a fatal error when you try to use an undefined class. The solution is to add a class, which can be included in a file. After all, you know which class to use. However, PHP provides a class Autoloading function, which can save programming time. When you try to use a class that PHP has not organized into, it will look for a global function __autoload. If this function exists, PHP will call it with a parameter, which is the class name. Example 6.15 illustrates how __autoload is used. It assumes that each file in the current directory corresponds to a class. When the script attempts to generate an instance of class User, PHP will execute __autoload. The script assumes that class_User.php defines There is a User class. Regardless of whether the call is in uppercase or lowercase, PHP will return the lowercase version of the name. Listing 6.15 Class autoloading name = "Leon"; $u->printName(); ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532153.htmlTechArticle| = This article is read by Haohappy> | = Notes from the Chapter Classes and Objects| = Translated mainly + personal Thoughts | = Please do not reprint to avoid possible unnecessary trouble, thank you | = Criticisms and suggestions are welcome...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn