First off, I'll admit that I'm anal about such things. (Bad, bad, me.) However, I'm just wondering what's considered best practice in terms of naming PHP include files.
As a base case I'm going to keep .php as the final extension (to help prevent un-parsed files being fetched), but to aid distinguishing between a front end file and an include file I'm either going to:
Name all of the include files XXX.inc.php
Name generic (non class) files as above and class definitions as ClassName.class.php (Potentially handy for auto-loader utilisation down the line, although I'm not a big fan of auto loaders.)
I'm currently plumping for option 2, but I'm just wondering if there are any other suggestions or bits of advice you'd recommend.
PHP Include Files. The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
The term . php file extension refers to the name of a file with a PHP script or source code that has a ". PHP" extension at the end of it.
If they are used trough include or require , any extension will work.
First of all, I totally agree with you when you say that all PHP files should have ".php" as a final extension ; two reasons for that :
There are cases when I do otherwise, though ; the main reason for that is when I'm using a tool (CMS, Framerwork, library, ...) that has some rules about naming of files : I tend to follow those, even if I don't like them.
For instance :
For files that contain classes, I don't like ".class.php" : I think it's kinda redundant ; I tend to use "MyClassName.php", and use this for autoload.
(BTW, that's what Frameworks like Zend Framework or Doctrine ORM recommend)
As a sidenote : you say you are not a big fan of autoloaders ; why ?
I use those as much as I can :
require
/include
)I use ClassName.class.php
for class files and SomeDescription.lib.php
for non-class files.
Not a fan of .inc.php
. Seems somehow wrong to describe the file in terms of how it may possibly be imported, instead of its content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With