Open In App

PHP get_defined_functions() Function

Last Updated : 28 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The get_defined_functions() function is an inbuilt function in PHP which returns the all defined functions in the array format.

Syntax:

array get_defined_functions( bool $exclude_disabled = true )

Parameters: This function accepts one parameter that is described below:

  • $exclude_disabled: It will check whether the disabled functions will be excluded from the return value i.e. if the function is false, it returns a value otherwise it will return the full definition of the function.

Return value: The return value will be a multidimensional array that has the list of all defined functions(ie., both built-in and user-defined). This function returns a definition of the function or returns the value of the function if the parameter will be true.

Example 1: In this example, we demonstrated the get_defined_functions() function.

PHP




<?php
    function hello_world(){
        echo "GeeksforGeeks";
    }
    $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
           [7] => strcasecmp
           [8] => strncasecmp
           [9] => error_reporting
           [10] => define
           [11] => defined
}     [user] => Array
       (
           [0] => hello_world
       ) )
 

Example 2: In this example, we will print only user-defined functions in an array form.

PHP




<?php
    function hello_world(){
        echo "GeeksforGeeks";
    }
    function bye_gfg(){
        echo "Bye GeeksforGeeks" ;
    }
    $arr = get_defined_functions();
        
    print_r($arr["user"]);
?>


Output:

Array
(
   [0] => hello_world
   [1] => bye_gfg
)

Reference: https://www.php.net/manual/en/function.get-defined-functions.php



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads