码迷,mamicode.com
首页 > 其他好文 > 详细

class_exists — 检查类是否已定义

时间:2016-02-03 18:17:48      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

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_exists — 检查类是否已定义

标签:

原文地址:http://www.cnblogs.com/zhouguowei/p/5180283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!