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
)
1

3 Answers 3

4

You can print defined functions as follows:

$arr = get_defined_functions();

print_r($arr);

Documentation here

Sign up to request clarification or add additional context in comments.

Comments

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
        )

)

Comments

2
<?php
$functions = get_defined_functions();

$user_defined_functions = $functions["user"];
var_dump($user_defined_functions);
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.