php查詢類的方法總結
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦
在php中,可以使用get_class_methods()函數(shù)來查詢類里面有哪些方法。
get_class_methods()函數(shù)可以獲取類的所有方法,返回由類的方法名組成的數(shù)組。
語法:
get_class_methods($class_name)
$class_name:類名或者對象實例。
返回值:返回由 $class_name 指定的類中定義的方法名所組成的數(shù)組。如果出錯,則返回 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_name<br>";
}
?>輸出結果:
myclass
myfunc1
mufunc2
實例擴展:
<?php
?class user
?{
??var $usertable;
??function get_oneuser($field,$value)
??{
???$field_array=array("id","name");? //查詢方式
???if(in_array($field,$field_array))
???{
????$sql="SELECT * FROM `$this->usertable` WHERE $field='$value'";
????$db=new database;
????$res=$db->execute($sql);
????$obj_user=mysql_fetch_object($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;
??}
?}
?>到此這篇關于php查詢類的方法總結的文章就介紹到這了,更多相關php怎么查詢類里面有哪些方法內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
php數(shù)組合并array_merge()函數(shù)使用注意事項
array_merge()函數(shù)在php中是對數(shù)組進行合并的,可以把多個數(shù)組合成一個數(shù)組,并且不改變原數(shù)組(www.111cn.net)的值了,但今天我在使用array_merge合并數(shù)組時碰到幾個小細節(jié)上的問題,下面我舉例子給各位朋友看看2014-06-06
PHP中soap用法示例【SoapServer服務端與SoapClient客戶端編寫】
這篇文章主要介紹了PHP中soap用法,結合實例形式分析了SoapServer服務端與SoapClient客戶端相關實現(xiàn)技巧與操作注意事項,需要的朋友可以參考下2018-12-12
Array of country list in PHP with Zend Framework
Array of country list in PHP with Zend Framework,需要的朋友可以參考下。2011-10-10
PHP實現(xiàn)二維數(shù)組按指定的鍵名排序的方法示例
這篇文章主要介紹了PHP實現(xiàn)二維數(shù)組按指定的鍵名排序的方法,這里以數(shù)組記錄三個人信息中的年齡age字段值進行排序為例,分析了php二維數(shù)組排序的操作技巧,需要的朋友可以參考下2017-08-08

