开发者

PHP file naming conventions (.class, .inc)

I see .class and .inc included in file names a lot of the tim开发者_如何转开发e. My current understanding is that this is just a best practice to make the purpose/contents of the file clear.

Is there any instance in PHP where a .class or .inc file name has a special purpose and truly means something?


As far as the PHP interpreter is concerned there's no behavioural reason to include these descriptors at all. The de facto convention seem to be, to include them as part of the file suffix however I find it more useful to prefix them - i.e. my file names tend to look like:

class.*.php
inc.*.php
tpl.*.php

This is purely for organisational purposes; Whenever an application / terminal lists them in alphanumerical order each "type" will be grouped together. To conclude the question though it's really just down to preference, the only thing that's important - whatever you choose - is consistency.


Not really

Depending on how you have your .htaccess file set up, it can determine which classes are visible to the world. I believe best practice still says to end every file with .php if you can.


I make my class files end with .class.php so I can see it's a class but no-one can view the source.


It is suggested by PHP best practice coding standards to name classes with class keyword somewhere in the class file name. However, the final decision is yours whether you want to stick with that or not. It has nothing to do with code execution.


In my opinion the best practice is to use a Framework and use the same naming conventions they uses in their sample projects. I don't think there is a Standard for it since it doesn't make a difference.

Most people name their classes as *.class.php and their static files as *.inc.php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜