<?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;//判断一个对象是否是属于一个类所实例化出来的。