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);
}
?>