Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Alan Knowles' Blog:
require_once as Documentation
Mar 29, 2005 @ 13:24:30

Alan Knowles has a new post on his blog today with a little "pet peeve" of several of the developers out there - the use of assumed includes in frameworks, causing problems down the road.

I had the pleasure (pun intended) of installing a small framework of code today, which broke at least half of the rules I've been building up for the projects I've been working on. The code illustrated very clearly why explicitly typing require_once is not only good idea, it can make the difference between clear readable code, and poor magic.

[...] The framework is supposed to have loaded this file, but as it's not set up correctly, and therefore, it didnt happen. To me this assumption that the file is loaded is flawed to begin with. Ignoring the issue that the framework relies on function libraries, the other fatal flaw is that Frameworks should rarely load more that one 'action' file, which in turn should be reasonably self explainitory where it is getting things from.

Since a require_once does help you locate the libraries that the scrit uses, it can be helpful in that respect, but it needs to be used with more care than most developers seem to want to worry about. He also makes mention of the __autoload functionality and how it can promote bad code design (less self-documenting).

tagged:

Link:


Trending Topics: