0

how can i print the array of all defined functions ?
sometimes a very complex php include many other files , and it has many common functions ,such as zencart pages , I want to find all functions of the page ,how to do?

<?php 

function hello(){}
function world(){}


// how to print all user defined functions?
array(
    [0] => hello
    [1] => world
)
linjuming
  • 2,117
  • 4
  • 23
  • 32
  • possible duplicate of [Function list of php file](http://stackoverflow.com/questions/2197851/function-list-of-php-file) and [PHP: Get PHP's variables, functions, constants from a php file](http://stackoverflow.com/questions/1858285/php-get-phps-variables-functions-constants-from-a-php-file) – jeremy Mar 30 '13 at 06:30

3 Answers3

4

You can print defined functions as follows:

$arr = get_defined_functions();

print_r($arr);

Documentation here

karthikr
  • 97,368
  • 26
  • 197
  • 188
3

You're looking for the get_defined_functions() function. You can read more about it at php.net (http://php.net/manual/en/function.get-defined-functions.php).

From the example at php.net

<?php
function myrow($id, $data) {
    return "<tr><th>$id</th><td>$data</td></tr>\n";
}

$arr = get_defined_functions();

print_r($arr);
?>

Output

Array
(
    [internal] => Array
        (
            [0] => zend_version
            [1] => func_num_args
            [2] => func_get_arg
            [3] => func_get_args
            [4] => strlen
            [5] => strcmp
            [6] => strncmp
            ...
            [750] => bcscale
            [751] => bccomp
        )

    [user] => Array
        (
            [0] => myrow
        )

)
Jakob Pogulis
  • 1,150
  • 2
  • 9
  • 19
2
<?php
$functions = get_defined_functions();

$user_defined_functions = $functions["user"];
var_dump($user_defined_functions);
?>
Satya
  • 8,693
  • 5
  • 34
  • 55