Get a list of all the member functions of an object WITHOUT being able to see the object code

StackOverflow https://stackoverflow.com/questions/16940475

  •  31-05-2022
  •  | 
  •  

How would I go about doing this? I know about get_object_vars, print_r, and var_dump, but those only seem to show me member properties. I need to see member functions.

I can see the "Title" property for example, but how do I know whether or not there's a getTitle / setTitle function without being able to see the object code? (and without tediously testing get/set functions for each variable)

有帮助吗?

解决方案

Take a look at ReflectionClass.

<?php
class Member {
    public function getName() {

    }
    public function getRanking() {

    }
}

$member = new ReflectionClass('Member');

foreach($member->getMethods() as $method) {
    echo $method->getName(), PHP_EOL;
}

/*
    getName
    getRanking
*/

Anthony.

其他提示

use get_class_methods() like this get_class_methods('classname');

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top