• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

nSiteful Web Builders

Building a Better Web - One Site at a Time.

  • Home
  • About
    • Testimonials
    • Resources
  • Web Sites
  • Online Marketing
  • WordPress Support
    • Customized WordPress Training
    • 60-for-60 Sessions
  • Web Applications
  • Blog
    • Archive Listing Minimalistic
    • Blog Articles Grouped by Category
    • Case Studies
    • General
    • Portfolio
    • Reviews
    • Snippets
    • Techniques
  • Contact Jeff
    • Purchase Retainer Consulting Hours
    • About Retainer Consulting Hours

By Jeff Cohan, October 20, 2015

Diagnostic PHP: Get All Included Files

Last updated October 10th, 2018 at 08:05 am

Sometimes when developing, it’s helpful to echo some diagnostic information to the screen. Here’s some simple diagnostic PHP I use for displaying all included files.

Define this function:

function diag_included_files( $sort = true, $echo = true ) {
	$inc_files =  get_included_files();
	if ( $sort ) {
		sort($inc_files);
	}
	if ( $echo ) {
		echo 'Included Files:<pre>' . print_r($inc_files, true) . '</pre>';
	} else {
		return $inc_files;
	}
}

The above function uses the native php get_included_files function, which returns a numeric array consisting of all files included by the include, include_once, require, and require_once functions. The array also includes the script that calls the function.

If you want the list of included files to appear in the order in which they are included, call the function with the first argument set to false, like this:

diag_included_files(0); // $sort = false

The result will look something like this (the function is being called from the history-report.php file):

Included Files:
Array
(
	[0] => /home/user/public_html/crm/history-report.php
	[1] => /home/user/public_html/crm/_includes/setup.php
	[2] => /home/user/public_html/crm/_includes/functions.php
	[3] => /home/user/public_html/crm/_includes/functions_utils.php
	[4] => /home/user/public_html/crm/_includes/functions_datetime.php
	[5] => /home/user/public_html/crm/_includes/class-nwb-form.php
	[6] => /home/user/public_html/crm/_includes/functions_validations.php
	[7] => /home/user/public_html/crm/_includes/functions_assembly.php
	[8] => /home/user/public_html/crm/_includes/functions_formdefs.php
	[9] => /home/user/public_html/crm/_includes/pagetop.php
	[10] => /home/user/public_html/crm/_includes/nav_main.php
	[11] => /home/user/public_html/crm/_includes/nav_hist.php
)

Sometimes, especially if there are many included files and you’re searching for specific ones, it’s best to sort the files alphabetically. In that case your call would look like this…

diag_included_files(1); // arg #1 for $sort = true; could leave blank

…and the result will look like this:

Included Files:
Array
(
    [0] => /home/user/public_html/crm/_includes/class-nwb-form.php
    [1] => /home/user/public_html/crm/_includes/functions.php
    [2] => /home/user/public_html/crm/_includes/functions_assembly.php
    [3] => /home/user/public_html/crm/_includes/functions_datetime.php
    [4] => /home/user/public_html/crm/_includes/functions_formdefs.php
    [5] => /home/user/public_html/crm/_includes/functions_utils.php
    [6] => /home/user/public_html/crm/_includes/functions_validations.php
    [7] => /home/user/public_html/crm/_includes/nav_hist.php
    [8] => /home/user/public_html/crm/_includes/nav_main.php
    [9] => /home/user/public_html/crm/_includes/pagetop.php
    [10] => /home/user/public_html/crm/_includes/setup.php
    [11] => /home/user/public_html/crm/history-report.php
)

Note that in both cases, I left the second argument ( $echo ) at the default of true, so that the result of the function would be echoed to the screen rather than returned.

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.

Related Posts

  1. Why, When, and How to use sprintf and printf
  2. Case Study: Emergency Notice Banner for Hybrid Web site
  3. Diagnostic PHP: Get All User Functions
  4. Diagnostic PHP: Get All User Constants
  5. PHP OOP Virtual Study Group?
  • Choose the best match.

Written by Jeff Cohan · Categorized: Snippets · Tagged: Diagnostics, php

  • Choose the best match.

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

mailchimp signup

Subscribe to get notified when new articles are published. Unsubscribe any time. No spam. I promise. Check out my newsletter archives.

social

Twitter Facebook LinkedIn

Recent Articles

  • Use Case for Custom Post Type: “In The News” March 10, 2023
  • Create a Custom Shortcode to Display a MemberPress Membership Price ANYWHERE on Your Website February 5, 2023
  • Avoid Direct Styling; Use CSS Instead September 21, 2022
  • Blog Tags: What They Are (and What They’re Not) August 5, 2022
  • How to Create a Simple Custom Events Plugin May 24, 2022

Filter By Category/Tag

Categories

  • Case Studies (7)
  • General (61)
  • Portfolio (5)
  • Reviews (12)
  • Snippets (16)
  • Techniques (38)

Popular Tags

Advanced Custom Fields Blogging Child Themes Content Marketing CSS CSS Grid Customer Service Custom Fields Custom Post Types Diagnostics Facebook FooGallery Genesis Gutenberg HTML Images iPhone Libra Live Chat Marketing Media MemberPress MemberPress Courses mu-plugins MySQL Photo Gallery php Pinterest Plugins Post Formats Pricing Project Management Security SEO Seth Godin Shortcodes Social Networking Surveys Taxonomies Trello Twitter Video Web design Web forms WordPress

siteground wp hosting

Web Hosting

wp101

EasyWordPresstutorialvideosforbeginners.
MemberPress CTA

Footer

Background

Web Sites | WordPress Support | Web Applications.

Formally trained in liberal arts and education (I have a B.A. in Government from Harvard and studied Secondary Education at Rutgers Graduate School), I have honed my skills in the communication arts and sciences as a teacher, trainer, instructional designer, writer, photographer, calligrapher, helpdesk manager, database programmer, and multimedia developer.

(I've also been a group counselor, waiter, bartender, bicycle messenger boy, computer salesman, carpenter's helper, financial analyst, and school board president.)

Tech

Systems since 1983.
Web sites since 1994.
PHP since 2001.
WordPress since 2007.

Contact

770-772-5134
Email Jeff
Send Money
All Ways

Copyright 2023, nSiteful Web Builders, Inc.

 

Subscribe

Pardon the interruption. I know popups can be annoying. But I’d love to have you as a subscriber.

Sign up to be notified when new articles are published. Unsubscribe any time.

* indicates required

Powered by MailChimp

×