what the naming convention for php files and folders?

underscore vs hyphen?

That’s an excellent question, especially when you are building a project that mixes multiple technologies like PHP, Docker, and shell scripts! Consistency in naming is key to maintaining clean and understandable code.

For your specific project structure and files:

php-docker-reporter/
├── Dockerfile
├── build.sh
├── docker-entrypoint.sh
├── docker_report.php
├── nginx.conf
└── run.sh

💻 Naming Conventions Breakdown

The conventions for PHP files and folders are generally guided by the PHP Standard Recommendations (PSRs) and common industry practices.

1. PHP Files (.php)

Naming StyleExampleBest PracticeRationale / Context
Underscore (_)docker_report.phpRecommendedHistorically the most common PHP style. It improves readability for functional files (scripts) and file names that correspond to class names (PSR-4 uses ClassName.php, but for non-class scripts, underscores are fine).
Hyphen (-)docker-report.phpDiscouragedWhile technically allowed, hyphens can be interpreted as subtraction operators if they are used in certain contexts (like class or function names), which can be confusing. It is generally avoided in the PHP world.
CamelCaseDockerReport.phpRequired (for Classes)If the file contains a PHP Class, PSR-4 requires the filename to match the class name exactly (e.g., class DockerReport must be in DockerReport.php).

✅ Conclusion for docker_report.php: Your current use of docker_report.php (using an underscore) is excellent for a functional script file.

2. General Files (Shell Scripts, Configs)

For files that are not PHP code (like shell scripts, Dockerfiles, or config files), the convention often shifts to follow the style preferred by the environment or the operating system.

File TypeNaming StyleBest PracticeRationale
Shell Scriptshyphen-case or underscore_caseHyphen (-)Unix/Linux scripting often favors hyphens for readability and consistency with many command-line utilities. However, both hyphens and underscores are very common.
Configuration Fileshyphen-case or dot.separatedHyphen (-)Following the standards of the tool itself (e.g., nginx.conf has no hyphen, but a log file might be access-log).
Docker-related fileshyphen-caseHyphen (-)Files like docker-compose.yml and docker-entrypoint.sh often use hyphens for clarity.

✅ Conclusion for your scripts:

  • docker-entrypoint.sh: Hyphen is a great, conventional choice for this file.
  • build.sh, run.sh: Simple, clear, and conventional.
  • nginx.conf, Dockerfile: These follow the specific naming rules of their tools.

3. Folder/Project Naming

Naming StyleExampleBest PracticeRationale
Hyphen (-)php-docker-reporterRecommendedThis is the standard convention for directory names in Unix/Linux environments and is strongly preferred for Git repositories, URLs, and general package names. It is also the style used for your initial repository name.
Underscore (_)php_docker_reporterDiscouragedUnderscores can be harder to read in URLs, and hyphens are overwhelmingly preferred for public project/package names.

✅ Conclusion for your project name: Your choice of php-docker-reporter (using hyphens) is the ideal and industry-standard choice for a top-level project directory.


⭐️ Summary of Your Project Naming

Your current structure is already highly consistent and follows all the standard best practices:

File NameNaming StyleConvention Followed
php-docker-reporter/ (Directory)HyphenStandard for package/project names and Unix directories.
docker_report.php (PHP Script)UnderscoreStandard for functional PHP script files.
docker-entrypoint.sh (Shell Script)HyphenStandard for shell scripts and Docker-related files.
Dockerfile, nginx.confTool SpecificFollows the required naming of the underlying tools.

In short, you do not need to make any changes to your current file names! They are perfectly aligned with conventional naming practices.

Leave a Reply