Last updated October 10th, 2018 at 08:04 am
Sometimes I want to see all the user-defined functions that are in memory when a page loads. Maybe the page doesn’t need certain functions and I can realize performance improvements by removing them. And sometimes — I’m being candid here — I copy functions from one application into a library file for another and don’t need any of them for the current application. This function, offering some diagnostic PHP, helps.
function diag_defined_user_fuctions( $sort = true, $echo = true ) { $funcs = get_defined_functions(); $u_funcs = $funcs['user']; if ( $sort ) { sort($u_funcs); } if ( $echo ) { echo 'User Functions:<pre>' . print_r($u_funcs, true) . '</pre>'; } else { return $u_funcs; } }
The native PHP function get_defined_functions returns a multidimensional array consisting of all defined functions, including internal functions and user-defined functions.
By calling my function with the default arguments (
diag_defined_user_fuctions();
… I get a result that looks like this:
User Functions: Array ( [0] => all_session_elements [1] => arrigate_disallowed_email_chars [2] => arrigate_disallowed_href_chars [3] => calendar_date [4] => callout_box [5] => check_convert_date_entry [6] => cmp [7] => convert_any_datestring_for_mysql [8] => convert_date_ymd [9] => convert_date_ymd_to_serial [10] => convert_datetime [11] => convert_time [12] => crm_browse_contacts [13] => crm_common_subjects [14] => crm_get_clients [15] => crm_get_contact [16] => crm_get_contacts [17] => crm_get_history [18] => crm_get_history_record [19] => crm_get_latest_balance [20] => crm_get_projects [21] => crm_get_recent_activity [22] => crm_get_res_uses [23] => crm_get_result_code_data [...] => etc....
If you have questions or comments about this snippet of diagnostic PHP — or if you have some of your own diagnostic PHP to share — feel free to leave a comment.
Leave a Reply