Include Files From Folder On A Easy Way

If you want to include files from a whole folder like this:

require_once( 'hubspot-api/func.baseclient.php' );
require_once( 'hubspot-api/func.leads.php' );
require_once( 'hubspot-api/func.settings.php' );
require_once( 'hubspot-api/func.leadnurturing.php' );
require_once( 'hubspot-api/func.prospects.php' );
require_once( 'hubspot-api/func.keywords.php' );
require_once( 'hubspot-api/func.blog.php' );
require_once( 'hubspot-api/func.contacts.php' );
require_once( 'hubspot-api/func.workflows.php' );
require_once( 'hubspot-api/func.forms.php' );
require_once( 'hubspot-api/func.lists.php' );
require_once( 'hubspot-api/func.properties.php' );
require_once( 'hubspot-api/func.socialmedia.php' );

.. use glob in conjunction with foreach instead of the solution above:

foreach( glob('hubspot-api/func.*.php') as $filename )
{
    require_once( $filename );
}

That’s it!

PS: For PHP classes, it’s recommended to use Autoloading Classes.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Tags:
php