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