php獲取類的所有方法的方法:可以利用get_class_methods()函數(shù)來獲取。get_class_methods()函數(shù)返回由類的方法名組成的數(shù)組,如果失敗則返回NULL。
get_class_methods()函數(shù)返回由類的方法名組成的數(shù)組。
(推薦教程:php圖文教程)
語法:
array get_class_methods ( mixed $class_name )
返回由 class_name 指定的類中定義的方法名所組成的數(shù)組。如果出錯(cuò),則返回 NULL。
注意:從 PHP 4.0.6 開始,可以指定對(duì)象本身來代替 class_name。
(視頻教程推薦:php視頻教程)
例如:
<?php $class_methods = get_class_methods($my_object); // see below the full example ?>
代碼示例:
<?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"; }
輸出結(jié)果:
myclass myfunc1 myfunc2