PHP - Should a class have the same name as the file?

advertisements

Does a class need to have the same name as it's file.

Ex. class.mysql.php and inside it having class mysql (same)

Ex. class.fish.php and inside it having class mysql (diff)

Also can the format for a class file name be name.class.php or does it have to be class.name.php?

Thank You


There is no link between the file name and the class name, you can name the classes in a file anything you want, have multiple classes or have no classes at all. However, it is a good idea to develop a consistent convention to indicate what the file contains via its file name.