Home > Backend Development > PHP Tutorial > PHP autoload classes

PHP autoload classes

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:06:53
Original
964 people have browsed it
<span style="white-space:pre">	</span>方法一:在类外面写
		function __autoload($name){
Copy after login
<span style="white-space:pre">			</span>//处理$name,获得类路径
			include $name_path;
		}
	
	//类内注册
	class ClassA{
Copy after login
<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;
Copy after login
}}

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.

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template