Is there any convention for naming php files? Not talking about php class files, but files that are mostly HTML with some php inside them. Should it be my-file-example.php
or myFileExample.php
or myfileexample.php
?
asked May 18, 2017 at 8:21
2
PSR-4 recommends using a directory hierarchy to represent the namespace.
For Object-Oriented programming,
the autoloader can simplify code management with relatively little cost overhead at run time. This requires the capability to determine a file path from a class name - hence a linear transform of the latter is a good idea. This might be as simple as $className . ".php"
answered May 18, 2017 at 8:34
symcbeansymcbean
46.9k6 gold badges56 silver badges90 bronze badges
I would suggest you to use underscore separators
my_file_example.php
, CodeIgniter for example use this convention for it's view files.
With dashes, some IDE/Text Editor don't select all the filname by double clicking on it, while with underscore it select, generally, all the file name.
answered May 18, 2017 at 8:26
There are usually 2 conventions you need to take into consideration:
- used framework
- PSR-4
In best scenario these 2 are the same. I usually try to avoid cases when a framework tries to force some custom rules.
Either way, the MOST important is to stay consistent throughout the project. Once you pick a convention to follow, stick with it until you start working on a different project. There's nothing worse than different naming conventions in a single project, doesn't matter if we're talking about files, classes, methods or whatever. Be consistent.
answered May 18, 2017 at 8:45
waltherwalther
13.3k5 gold badges40 silver badges64 bronze badges
There is no really convention for PHP files.
You just should keep the same in your project.
I recommand you to use camelCase.
answered May 18, 2017 at 8:24
ZoolyZooly
4,6404 gold badges33 silver badges52 bronze badges
1
There is no specific for the core php files you have to use your own naming convention, but you can name on the bases of you file work.
Like php file is only display
the html then give my_file_view.php
if it has database operation then my_file_db.php
and so on for the function and for other specification you can use it.
DarkBee
15.9k5 gold badges47 silver badges56 bronze badges
answered May 18, 2017 at 8:36
AmanAman
212 bronze badges
I use PascalCase for directory names, PHP class files and class names and for other things I use camelCase.
answered Sep 2, 2021 at 16:48
MRE20MRE20
294 bronze badges
You'll come across packages using filenames as
class.phpmailer.php or
ImapMailbox.php
[both containing classes with ClassName {}]
[Personally, I use camelCase heavily for fnames, from var-habits i guess. ]
answered May 18, 2017 at 8:37
TesonTeson
6,4547 gold badges42 silver badges67 bronze badges
2