Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Emmanuele Massimi
Emmanuele Massimi
7,420 Points

Include single function from an external file

Hi all,

I am trying to place all the shared functions of my project into a single file. However, I wouldn't like to include the whole file when all I need is a single function, for example.

Is there any way to include a single function from an external file? Also, in terms of performance, is there any impact whether I import the whole file or just a single function?

Thank you for your time!

2 Answers

Richmond Lauman
Richmond Lauman
28,793 Points

I am not sure why you would want to include only specific functions from one file containing many. Unless you have A LOT of functions on one file to the point where it might slow the page load speed down to include all of them. It would take an awful lot of functions to slow the page load time I would think. If that were a problem, you could look at what different pages might specifically need and create specific include files for certain page types, containing only the functions needed in bundles customized for certain pages.

Emmanuele Massimi
Emmanuele Massimi
7,420 Points

So, I take it that it's not possible to do that currently in PHP, however, thanks for your suggestions :)