Functions

Consider using include_once() and require_once() to avoid possible errors caused by one file being included several times. This is particularly important when you define a class in one file, and other programmers try to use it.

It is generally good practice to put commonly used functions into a standard include file, that is used with include_once() at the start of scripts that need it. If you adopt this method and end up having some functions local to each script, you may wish to name them so as to make it clear that they are local so that people do not look for them in the standard include file.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Distinguishing code blocks >>

Previous chapter: Variable naming

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.