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 Style | Example | Best Practice | Rationale / Context |
Underscore (_) | docker_report.php | Recommended | Historically 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.php | Discouraged | While 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. |
| CamelCase | DockerReport.php | Required (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 Type | Naming Style | Best Practice | Rationale |
| Shell Scripts | hyphen-case or underscore_case | Hyphen (-) | Unix/Linux scripting often favors hyphens for readability and consistency with many command-line utilities. However, both hyphens and underscores are very common. |
| Configuration Files | hyphen-case or dot.separated | Hyphen (-) | Following the standards of the tool itself (e.g., nginx.conf has no hyphen, but a log file might be access-log). |
| Docker-related files | hyphen-case | Hyphen (-) | 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 Style | Example | Best Practice | Rationale |
Hyphen (-) | php-docker-reporter | Recommended | This 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_reporter | Discouraged | Underscores 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 Name | Naming Style | Convention Followed |
php-docker-reporter/ (Directory) | Hyphen | Standard for package/project names and Unix directories. |
docker_report.php (PHP Script) | Underscore | Standard for functional PHP script files. |
docker-entrypoint.sh (Shell Script) | Hyphen | Standard for shell scripts and Docker-related files. |
Dockerfile, nginx.conf | Tool Specific | Follows 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.
