zoukankan      html  css  js  c++  java
  • 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);
    }

    ?> 

  • 相关阅读:
    Java引用类型转换
    SWFUpload多文件上传使用指南
    SpringMVC中与Spring相关的@注解
    三层——c#版
    初识三层
    vb.net 总结
    设计模式总结
    设计模式系列——装饰模式
    设计模式系列——策略模式
    设计模式系列——简单工厂模式
  • 原文地址:https://www.cnblogs.com/zhouguowei/p/5180283.html
Copyright © 2011-2022 走看看