cola
cola

Reputation: 12486

How can i get the function name from a .php file ? Need a php script

Suppose there is a input file. The file contains php class with many functions and public variable.

I need a php script that would take that input file and count how many php function are there. This script will also print the function name like ..

public function hasMethod($method)
public function isVirtualField($field)

Can anyone post such php script to do this ?

Upvotes: 2

Views: 236

Answers (2)

konsolenfreddy
konsolenfreddy

Reputation: 9671

get_class_methods() will give you all methods in a given object or class name, see PHP func ref

require_once('Model.php');
$methods = get_class_methods('Model');
print_r($methods);

Will show you all methods of the class Model in file Model.php

Upvotes: 4

Gerhard
Gerhard

Reputation: 131

class theclass {
    // constructor
    function theclass() {
        return;
    }

    function func1() {
        return;
    }

    // method 2
    function func2() {
        return;
    }
}

    $class_methods = get_class_methods('theclass');

foreach ($classFunctions as $functionName) {
    echo "$functionName\n";
}

Upvotes: 1

Related Questions