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
  •  | 
  •  

Question

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)

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top