Prev | Current Page 185 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

This will soon become apparent.
The next chapter is devoted to the construction and invocation of functions, reusable
chunks of code intended to perform a specific task. This material starts you down the
path necessary to begin building modular, reusable PHP applications.
113
?–  ?–  ?– 
C H A P T E R 4
Functions
Computer programming exists in order to automate tasks of all sorts, from mortgage
payment calculation to determining a person??™s daily recommended caloric intake.
However, as these tasks grow increasingly complex, you??™ll often find they comprise
other often repetitive tasks. For example, an e-commerce application might need to
validate an e-mail address on several different pages, such as when a new user registers
to use a Web site, when somebody wants to add a product review, or when a visitor
signs up for a newsletter. The regular expression used to validate an e-mail address is
quite complex, and therefore it would be ideal to maintain it in a single location rather
than embed it into numerous pages, particularly if it needs to be modified to account for
a new domain (such as .museum).
Thankfully, the concept of embodying these repetitive processes within a named
section of code and then invoking this name when necessary has long been a key
component of modern computer languages. Such a section of code is known as a
function, and it grants you the convenience of a singular point of reference if the
process it defines requires changes in the future, which greatly reduces both the
possibility of programming errors and maintenance overhead.


Pages:
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197