要想查看php中類(lèi)的方法,我們可以利用get_class_methods()方法來(lái)實(shí)現(xiàn)。該函數(shù)可以返回由類(lèi)的方法名組成的數(shù)組,例如:【get_class_methods($my_object)】。
get_class_methods — 返回由類(lèi)的方法名組成的數(shù)組。
(推薦教程:php圖文教程)
說(shuō)明
array get_class_methods ( mixed $class_name )
返回由 class_name 指定的類(lèi)中定義的方法名所組成的數(shù)組。如果出錯(cuò),則返回 NULL。
注意: 從 PHP 4.0.6 開(kāi)始,可以指定對(duì)象本身來(lái)代替 class_name,例如
<?php $class_methods = get_class_methods($my_object); // see below the full example ?>
(學(xué)習(xí)視頻推薦:php視頻教程)
舉例:
<?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"; }
輸出:
myclass myfunc1 myfunc2