Reuse Code: Introduction ( Part 1 )Tag: Reuse Code Category:post: 12 Nov 2007 read: 519 Than write new codes, it is more better we reuse existing code. This is one goal of software engineers. This is not because they are very lazy people. Reusing existing code will reduces cost, increases reliability, and improves consistency. This series tutorial will explains how reusing code leads to more consistent, reliable, maintainable code, with less efort. PHP provides two very simple statements to allow you to reuse any type of code. Yeah.. require() and include() statement. With these statement, you can load a file into your PHP script. The file can contain anything you would normally type in a script includeing PHP statements, text, HTML tags, PHP Functions, or PHP Classes. Include()(All sample below I rewrite from PHP manual) Basic include example(): "vars.php" file:
"test.php" file:
Require()
require() and include() are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well.
| ||
| | Give Your Opinion | Recommend |
|

