Greytree

TamWiki

For a mouse who is a packrat

Technology » Write Functions In A Separate Include
Accumulate a library of functions for reuse from project to project and enable easier testing

Summary:this is what goes at the top of the site

(redirected from Main.WriteFunctionsInASeparateInclude)

Many times, I'll find a function I've written can be reused in several places. Rather than storing the function in any particular script, I'll include it in a library file created just for that purpose. I call my library file functions.inc.php. In it, I put generic functions that can be used across different projects with some minor customization, or in many cases, no customization at all. Examples include some of the functions listed elsewhere.

My current PHP functions library is available from git repo.

Code reuse is a proven means to cut down on the time it takes to write an application. As one gets more experience writing applications, once can accumulate a significant library of code to reuse. It often takes just a little more work to make something reusable, but is well worth the effort.

I had been using the .inc extension on include files, but this is a really bad idea. Normally these files aren't interpretted by the PHP interpretter and are passed directly back to the browser as plain text. If they include sensitive code or data, this could be a real security breach. Instead, make sure to append .php to the file name so they will be interpretted instead.


Tags: Categories: Articles

Recent Changes | Printable View | Page History | Edit Page
Page last modified on April 17, 2012, at 08:59 PM by ImportText?