?– Tip A URL can be used with require() only if allow_url_fopen is enabled, which by default it is.
The second important difference is that script execution will stop if a require()
fails, whereas it may continue in the case of an include(). One possible explanation
for the failure of a require() statement is an incorrectly referenced target path.
Ensuring a File Is Required Only Once
As your site grows, you may find yourself redundantly including certain files. Although
this might not always be a problem, sometimes you will not want modified variables
in the included file to be overwritten by a later inclusion of the same file. Another
problem that arises is the clashing of function names should they exist in the inclusion
file. You can solve these problems with the require_once() function. Its prototype
follows:
112 CHAPTER 3 ?– PHP B ASICS
require_once (filename)
The require_once() function ensures that the inclusion file is included only once in
your script. After require_once() is encountered, any subsequent attempts to include
the same file will be ignored.
Other than the verification procedure of require_once(), all other aspects of the
function are the same as for require().
Summary
Although the material presented here is not as glamorous as the material in later
chapters, it is invaluable to your success as a PHP programmer because all subsequent
functionality is based on these building blocks.
Pages:
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196