简体   繁体   English

PHP文件命名约定(.class,.inc)

[英]PHP file naming conventions (.class, .inc)

I see .class and .inc included in file names a lot of the time. 我在很多时候都看到.class和.inc包含在文件名中。 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? 在PHP中是否存在.class或.inc文件名具有特殊用途且真正意味着什么的实例?

As far as the PHP interpreter is concerned there's no behavioural reason to include these descriptors at all. PHP解释器而言,根本没有包含这些描述符的行为理由。 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 - ie 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. 根据您设置.htaccess文件的方式,它可以确定哪些类对世界可见。 I believe best practice still says to end every file with .php if you can. 我相信如果可以,最佳做法仍然是用.php结束每个文件。

我使用.class.php结束我的类文件,所以我可以看到它是一个类,但没有人可以查看源代码。

It is suggested by PHP best practice coding standards to name classes with class keyword somewhere in the class file name. PHP最佳实践编码标准建议在类文件名中使用class关键字命名类。 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. 大多数人将他们的类命名为* .class.php,将他们的静态文件命名为* .inc.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM