PHP
Frameworks
CMS
PHP
Naming conventions – PHP
·
Here are the suggested naming conventions for Variables, Classes, Functions and Files.
Naming Variables
- Use all lower case.
- Use _ to separate words, e.g. $green_color_value
- Use descriptive names (except loop variables).
- Loop variables can be of the usual variety: $i, $j, $k, etc.
- Count variables should follow the format $*_count, e.g. $error_count
- Global variables should be prefixed with g_
- Temporary variables should be prefixed with t_
- Parameters and variables passed from forms that have been cleaned of any special SQL chars (i.e. slashes) should be prefixed with c_
- Never prefix with l_ or o_ or q_ (visually confusing)
- $query and $result should be used for SQL query and results respectively
Naming Classes
- Use FirstLetterOfWordIsCaptilized style
- Variables that are class objects should have the prefix coo_
Naming Functions
- Use all lower case.
- Use _ to separate words, e.g. setup_page_breaks()
- Keep functions to 5 words or less
- Functions that print should be prefixed with print_.
- Try to use prefixes to group functions (i.e., email_, news_, etc.)
Naming Files
- Use all lower case.
- Use _ to separate words, e.g. view_new_bugs_page.php
- Use .php file extensions
- Filenames must be less than 32 characters in length.
- Included files should be suffixed by _inc.php
Ready to Solve Your Most Complex Technical Challenges?
Our senior advisors are ready to help you navigate the ever-evolving technology landscape with precision and expertise.
Schedule a ConsultationRelated Articles
Laravel Interview Questions
Basic Laravel Interview Questions Q1: What is Laravel? Why is it used?A: Laravel is an open-source PHP framework designed for web application…
Solution for WordPress “too many redirects” issue
The “Too Many Redirects” issue on WordPress usually occurs due to misconfiguration in the site’s URL settings, SSL setup, or conflicts between…
PHP logic to reverse a string
<?php// Function to reverse a given stringfunction reverseText($text) { // Get the length of the input text $textLength = strlen($text); // Initialize…