filename for class files: file.class.php or file.php?

11,036

Solution 1

There is no standard per se for naming class files, however file.class.php sends the message that it contains class files, opposed to file.php which may give the impression of a regular file.

My suggestion is to use one convention and be consistent with it.

Update:

A good point to note, as AJ, had stated, the *.php file extension is preferred over *.inc file extensions. Reason being that *.inc files are displayed on the client's browser as plain text and if you were to store any configuration files or private information (especially in relation to your database, yikes) it could potentially be accessed by anyone.

Solution 2

Actually this method of naming files came from developers who combines both procedural & OOPs in a same built. To differentiate procedural files and class files they did this. There is no standard convention. But I will suggest you to use filename.php and name the class as same as file name, just as Java convention. Keep only one class definition in a file.

@Derk: It can also be like this, there is no benefit of adding class. in file name ;)

 function __autoload ($class) {

      require_once $class . '.php';

  }

  $pizza = new pizza ();
Share:
11,036

Related videos on Youtube

never_had_a_name
Author by

never_had_a_name

Updated on April 22, 2022

Comments

  • never_had_a_name
    never_had_a_name about 2 years

    i have seen a lot of coders choosing this filename convention:

    file.class.php.

    is this a standard of naming class files?

    just curious. so i know if i should follow it for all class files in the future.

    thanks

  • user1020069
    user1020069 about 12 years
    I don't think this is common at all.... .class.php file extension are the accepted norm
  • Gajus
    Gajus over 10 years
    Thats a terrible advice. Introducing case-sensitivity to file system is a way to get shot in the log: autoloader (on UNIX based systems) will need to try multiple file name combinations.