class_exists — 检查类是否已定义
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了class_exists — 检查类是否已定义相关的知识,希望对你有一定的参考价值。
class_exists — 检查类是否已定义
bool class_exists ( string $class_name [, bool $autoload = true ] )
检查指定的类是否已定义。
<?php
class Person{
public $username;
public $age;
public $height;
public $weight;
public function __construct($username,$age,$height,$weight){
$this->username = $username;
$this->age = $age;
$this->height = $height;
$this->weight = $weight;
}
public function __set($name,$value){
$this->$name = $value;
}
public function __get($name){
return $this->$name;
}
public function __toString(){
return ‘‘;
}
}
function __autoload($class){
include($class.‘.php‘);
if(!class_exists($class)){
trigger_error("Unable to load class: $class",E_USER_WARNING);
}
}
if(class_exists(‘Person‘)){
$p_person = new Person(‘zhaofei‘,23,185,72);
var_dump($p_person);
}
class Person{
public $username;
public $age;
public $height;
public $weight;
public function __construct($username,$age,$height,$weight){
$this->username = $username;
$this->age = $age;
$this->height = $height;
$this->weight = $weight;
}
public function __set($name,$value){
$this->$name = $value;
}
public function __get($name){
return $this->$name;
}
public function __toString(){
return ‘‘;
}
}
function __autoload($class){
include($class.‘.php‘);
if(!class_exists($class)){
trigger_error("Unable to load class: $class",E_USER_WARNING);
}
}
if(class_exists(‘Person‘)){
$p_person = new Person(‘zhaofei‘,23,185,72);
var_dump($p_person);
}
?>
以上是关于class_exists — 检查类是否已定义的主要内容,如果未能解决你的问题,请参考以下文章