php查询类的方法总结

2022-04-16 15:06:47

本教程操作环境:windows7系统、php7.1版、DELL G3电脑

在php中,可以使用get_class_methods()函数来查询类里面有哪些方法。

get_class_methods()函数可以获取类的所有方法,返回由类的方法名组成的数组。

语法:

get_class_methods($class_name)

$class_name:类名或者对象实例。

返回值:返回由 $class_name 指定的类中定义的方法名所组成的数组。如果出错,则返回 null。

示例:

<?php class myclass {    // constructor    function myclass()    {        return(true);    }     // method 1    function myfunc1()    {        return(true);    }     // method 2    function myfunc2()    {        return(true);    }} $class_methods = get_class_methods('myclass');// or$class_methods = get_class_methods(new myclass()); foreach ($class_methods as $method_name) {    echo "$method_res);return $obj_user;}else echo "查询方式不对";}function get_moreusers(){global $db;$argnums=func_num_args();$argarr=func_get_args();switch($argnums){case 0:$sql="SELECT * FROM `$this->usertable`";break;case 2:$sql="SELECT * FROM `$this->usertable` WHERE $argarr[0]='$argarr[1]'";break;case 4:$sql="SELECT * FROM `$this->usertable` WHERE $argarr[0]='$argarr[1]' AND $argarr[2]='$argarr[3]'";break;}//$db=new database;$res=$this->execute($sql);$obj_arr=array();while($obj=mysql_fetch_object($res)){$obj_arr[]=$obj;}return $obj_arr;}}?>

相关文章 大家在看