Home >Backend Development >PHP Tutorial >PHP autoload classes

PHP autoload classes

WBOY
WBOYOriginal
2016-07-29 09:06:53941browse
<span style="white-space:pre">	</span>方法一:在类外面写
		function __autoload($name){
<span style="white-space:pre">			</span>//处理$name,获得类路径
			include $name_path;
		}
	
	//类内注册
	class ClassA{
<span style="white-space:pre">		</span>public static $_autoload;
		public function __construct(){
			spl_autoload_register(array('ClassA','classAutoLoader'));
		}
		//ClassA 如果实例化可以不用静态方法
		public static function classAutoLoader($name){
			<pre name="code" class="php"><span style="white-space:pre">			</span>//处理$name,获得类路径
			include $name_path;
}}

The above introduces the PHP automatic loading class, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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