Diagnostic PHP: Get All User Functions

Share this!

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 ) {
	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 (

$sort = true and $echo = true)…


… I get a result that looks like this:

User Functions:

	[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.

Share this!

About JeffCohan.com

The nSiteful Tech Blog (the official blog of nSiteful Web Builders, Inc. since January of 2013) is where I (Jeff Cohan) and (occasionally) associates will be posting articles of potential interest to like-minded techies, nSiteful clients who are playing active roles in the maintenance of their own Web sites and blogs, and pretty much anyone interested in how Web strategies and tools can help them reach their goals.

This entry was posted in Snippets and tagged , , by Jeff Cohan. Bookmark the permalink.

About Jeff Cohan

Jeff and his wife, Margie, are the proud parents of Sarah and Jake. Jeff is the founder, president and chief cook and bottle washer of nSiteful Web Builders, Inc., a Web development and Internet Consulting firm. In his spare time, Jeff builds Web sites and Web applications, plays guitar, putters around in his basement woodworking shop, mercilessly spoils his grandchildren, and creates videos from more than two decades of home movies. His current video project is an extended montage of people (mainly family members) asking him to stop filming them.

Leave a Reply

Your email address will not be published. Required fields are marked *