zoukankan      html  css  js  c++  java
  • 019对象——对象 method_exists property_exists instanceof

    <?php
    /**
     * 19 对象 method_exists property_exists instanceof
     */
    
    
    //method_exists() 判断方法是否存在,第一个参数对象或类名,第二个参数是方法。
    class index{
        function indexs(){
            echo "后台登录首页";
        }
    }
    class arc{
        public $name;
        public $id;
        function index(){
            echo "显示栏目列表";
        }
        function del(){
            echo "删除栏目";
        }
        function add(){
            echo "追加栏目";
        }
    }
    /*$action=isset($_GET['a'])?$_GET['a']:'index';
    $method=isset($_GET['m'])?$_GET['m']:'indexs';
    $obj=new $action();
    //检测一个方法是否存在于一个对象中:
    if(method_exists($obj,$method)){ //$obj()获得对象   $method获得浏览器的方法
        $obj->$method();
    }else{
        die("非法调用方法");
    }*/
    
    //property_exists()判读在对象或类中是否有该属性,第一个参数可以是对象获取类名。第二个参数为属性名
    /*$arc=new arc();
    echo property_exists ($arc,'id');*/
    
    //判断一个对象是不是
    $obj=new arc();
    echo $obj instanceof arc;//判断一个对象是否是属于一个类所实例化出来的。
    

      

  • 相关阅读:
    Date类型 方法
    迭代方法和归并函数
    js快速排序方法
    reset
    水平垂直居中
    css清除浮动
    box-shadow
    display---我的第一篇博客
    centos7基础安装
    aws和ufile挂载数据盘EBS
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8041130.html
Copyright © 2011-2022 走看看