user2507818
user2507818

Reputation: 3037

How to output the methods from class

<?php
class A
    {
        public $attribute1;
        function operation1()
            {
                echo 'operation1';
            }
}
$a = new A();
var_dump($a);

It shows:

object(A)[1]
  public 'attribute1' => null

Question:

It outputs the property in class A, but if I want to see the methods/functions in class A, how could I do?

Upvotes: 1

Views: 46

Answers (2)

TienL
TienL

Reputation: 26

You can gets the class methods' names

$class_methods = get_class_methods('A');
// or
$class_methods = get_class_methods(new A());

foreach ($class_methods as $method_name) {
    echo "$method_name\n";
}

Upvotes: 1

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

Use get_class_methods to view the class function names.

$class_methods = get_class_methods(new A());

foreach ($class_methods as $method_name) {
    echo "$method_name\n";
}

Output

operation1

Upvotes: 1

Related Questions