Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use '.class.php' extension for PHP classes?

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.

like image 479
ale Avatar asked Jan 29 '26 18:01

ale


1 Answers

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
like image 196
Jon Avatar answered Feb 01 '26 08:02

Jon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!