Welcome Guest, Not a member yet? Register   Sign In
Is there a way to see all methods in a class?
#1

[eluser]tdktank59[/eluser]
So im working on creating a script and I need to be able to see all methods within a said class.

Is there a way to do this while in the script? Or is this something I have to manual do for each class?
#2

[eluser]pistolPete[/eluser]
How about get_class_methods()?
#3

[eluser]tdktank59[/eluser]
that would be it lol...

I looked through the whole OOP section couldn't find this.
I was looking in the wrong section

Thanks for the fast reply!
#4

[eluser]Brandon Jackson[/eluser]
Let's say you only want a list of the public methods in a class... this code will help by using the Reflection class.

Code:
foreach (get_class_methods($c) as $key => $val)
            {
                  /* Get a reflection object for the class method */
                       $reflect = new ReflectionMethod($c, $val);

                /* For private, use isPrivate().  For protected, use isProtected() */
                
                if($reflect->isPublic())
                {
                      if (!in_array($val,$this->invalid_methods))
                    {
                        // Put the methods we care about into an array
                        $method[$c][] = $val;
                    }
                }
            }




Theme © iAndrew 2016 - Forum software by © MyBB