donglu7286 2012-10-31 14:49
浏览 30
已采纳

对PHP类使用'.class.php'扩展名?

Is it common practice to append use '.class.php' extension for PHP classes?

On PHP.net here: http://php.net/manual/en/function.spl-autoload-register.php there are some examples like this:

// Or, using an anonymous function as of PHP 5.3.0
spl_autoload_register(function ($class) {
    include 'classes/' . $class . '.class.php';
});

which use a .class.php extension.

Should PHP code be written like this? I've never seen it before, is it something new? This is a kind of new feature in PHP so maybe it is?

EDIT: 'feature' was not a good word! Perhaps I should have asked whether it's some standard or convention.

Thanks.

  • 写回答

8条回答 默认 最新

  • dpea85385 2012-10-31 14:53
    关注

    It's not a feature, it's just a convention that you see come up every now and then. Whether to follow it or not is the choice of you and your team.

    My personal opinion is that since the choice is arbitrary and this particular style contradicts with the PSR-0 autoloader specification you should pass because:

    • PSR-0 is more widely used, so all other things being equal it would be a better convention to follow
    • following the ".class.php" style means cannot take a PSR-0 compliant autoloader (there are many online) and use it without modifications
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?