• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Article / PHP / Get a list of all available functions with PHP

Get a list of all available functions with PHP

PHP has the function get_defined_functions() which allows you to get a list of all the available system and user defined functions in an array. This post looks at how to use the get_defined_functions() function, the output from it and how to sort the list into alphabetical order.

Using get_defined_functions()

get_defined_functions() returns an array containing two keys: ‘internal’ and ‘user’. Each key contains a sub array containing a complete list of the available internal/system functions and the user defined functions respectively.

The following example illustrates this (the examples below assume we have two user defined functions called foo() and bar()):

print_r(get_defined_functions());

and an extract of the result:

Array
(
    [internal] => Array
        (
            [0] => zend_version
            [1] => func_num_args
            [2] => func_get_arg
            [3] => func_get_args
            [4] => strlen
            [5] => strcmp
            ...
            [1274] => xmlwriter_write_dtd_attlist
            [1275] => xmlwriter_output_memory
            [1276] => xmlwriter_flush
        )

    [user] => Array
        (
            [0] => foo
            [1] => bar
        )
)

Sorting the result into alphabetical order

If you want to sort the list of functions into alphabetical order, you could do this instead:

$functions = get_defined_functions();
sort($functions['internal']);
sort($functions['user']);
print_r($functions);

and an extract of the result:

Array
(
    [internal] => Array
        (
            [0] => _
            [1] => abs
            [2] => acos
            [3] => acosh
            [4] => addcslashes
            [5] => addslashes
            ...
            [1274] => zend_logo_guid
            [1275] => zend_version
            [1276] => zlib_get_coding_type
        )

    [user] => Array
        (
            [0] => bar
            [1] => foo
        )

)

Conclusion

The get_defined_functions() function is a great way of getting a complete list of functions that are available on your install of PHP and from your own and 3rd party PHP libraries.

Check Out These Related posts:

  1. Parsing Google Analytics data with PHP: A Series
  2. Using PHP IMAP functions to download email from Gmail
  3. Get unique array values with PHP
  4. Using PHP IMAP functions to download email

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap