Open In App

How to get all function names of a module in PHP ?

Last Updated : 18 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn How to get the names of all functions present in a module in PHP.

What is a module in PHP ?

A module is a collection of independent software components. The usage of modules in program improves the code reusability and encapsulation. Module contains functions that we can use these functions by including the module in our code. Now we are going to print all the functions present in a given module.

How to get the names of all functions of a module in PHP ?

To get the names of all functions of a PHP module, we can use get_extension_funcs() function. This function takes the name of module as an input argument and returns the array of function names as output.

Example 1: In this example, we will print all the functions present in JSON module.

PHP




<?php
  
$func_names = get_extension_funcs("DOM");
$length = count($func_names);
  
for($i = 0; $i < $length; $i++) {
    echo($func_names[$i]);
    echo("<br>");
}
?>


Output

dom_import_simplexml

Example 2: In this example we will print all the functions present in XML module. 

PHP




<?php
  
$func_names = get_extension_funcs("XML");
$length = count($func_names);
  
for($i = 0; $i < $length; $i++) {
    echo($func_names[$i]);
    echo("<br>");
}
?>


Output

xml_parser_create
xml_parser_create_ns
xml_set_object
xml_set_element_handler
xml_set_character_data_handler
xml_set_processing_instruction_handler
xml_set_default_handler
xml_set_unparsed_entity_decl_handler
xml_set_notation_decl_handler
xml_set_external_entity_ref_handler
xml_set_start_namespace_decl_handler
xml_set_end_namespace_decl_handler
xml_parse
xml_parse_into_struct
xml_get_error_code
xml_error_string
xml_get_current_line_number
xml_get_current_column_number
xml_get_current_byte_index
xml_parser_free
xml_parser_set_option
xml_parser_get_option
utf8_encode
utf8_decode

Example 3: In this example, we will print all the functions present in DOM module.

PHP




<?php
  
$func_names = get_extension_funcs("JSON");
$length = count($func_names);
  
for($i = 0; $i < $length; $i++) {
    echo($func_names[$i]);
    echo("<br>");
}
?>


Output

json_encode
json_decode
json_last_error
json_last_error_msg


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads