Brian
Brian

Reputation: 963

PHP file naming conventions (.class, .inc)

I see .class and .inc included in file names a lot of the time. 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?

Upvotes: 11

Views: 15451

Answers (5)

Emissary
Emissary

Reputation: 10148

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.

Upvotes: 14

Ian
Ian

Reputation: 51

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

Upvotes: 5

Sarfraz
Sarfraz

Reputation: 382696

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.

Upvotes: 3

Roch
Roch

Reputation: 22041

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.

Upvotes: 2

Joe Phillips
Joe Phillips

Reputation: 51120

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.

Upvotes: 9

Related Questions