PHP | Coding Standards Last Updated : 17 Feb, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report PHP follows few rules and maintains its style of coding. As there are many developers all over the world, if each of them follows different coding styles and standards this will raise great confusion and difficulty for a developer to understand another developer's code. It will be very hard to manage and store the code for future reference. The coding standards come into play for all the reasons. Reasons for maintaining coding standards: People working in different modules can easily manage the source code due to familiarity.Acts as a blueprint for other team members to understand the code for management or changes.Clarity saves a lot of time doing common mistakes as it's easy to understand.Coding standards or industry standards improve the quality and consistency of software. Below mentioned are few guidelines that one must follow in order to maintain the standard of PHP coding. PHP tags: One must use the PHP standard tags, rather than the shorthand tags to delimit the PHP code. Full tags : <?PHP PHP code ?> Short tags: <? PHP code ?>Comments: Use of standard C and C++ commenting style i.e., (//) for single line and (/* */) for multiple-line, is highly encouraged and use of Python or Perl style of commenting i.e., (#), is discouraged.Line length and Indentation: It is a standard recommendation to not exceed more than 75-85 characters per line of code. One must not use tabs for indentation instead use spaces as it is the standard indenting method in most programming languages. One statement per line or else split lines for long multiple ones.Control structures: The control flow or conditional statements must be written in such a way so that they could be differentiated from function call statements. While writing if, for, else, foreach, do, while, switch, and other controls flow statements there must be one space between the keyword and the opening parenthesis. The function definitions do not have any space between the function name and opening parenthesis.Function calls: There should be no spaces between parameters, comma, last parameter, and semicolon. Always use full PHP tags and avoid shorthand tags. Also, give one space between both sides of '=' operator. Example: PHP <?php $n = 5; if ($n > 0){ echo "Positive"; } elseif ($n < 0){ echo "Negative"; } else{ echo "Zero"; } ?> Output: Positive Example: PHP <?php echo testFunc(5, 6); function testFunc($num1, $num2) { $val = $num1 + $num2; return $val; } ?> Output: 11Naming variables: There are few conventions that one must follow in order to name the variables: Use of lower case letters to name the variables.Use of '_' to separate the words in a variable.Static variable names may be started with the letter 's'.Global variable names must start with the letter 'g'.Use of upper-case letters to define global constants with '_' as a separator.Block alignment : Every block of code and curly braces must be aligned.Short Functions: All functions and methods must limit themselves to a single page and must not be lengthy. Note: The above rules are provided just to make the code easily understandable and to manage the code easily. There will not be any specific error in case of violation of the rules mentioned above. But it is highly recommended following the above convention to improve the overall quality of code from a developer's perspective. Comment More infoAdvertise with us Next Article PHP String Functions C chinmoy lenka Follow Improve Article Tags : Misc Web Technologies PHP PHP-basics Practice Tags : Misc Similar Reads Getting Started with PHP PHP (Hypertext Preprocessor) is a powerful scripting language widely used for web development. Whether you're looking to create dynamic web pages, handle form data, interact with databases, or build web applications, PHP has you covered. In this guide, we'll take you through the basics of PHP, cover 7 min read PHP String Functions Strings are a fundamental data type in PHP, used to store and manipulate text. PHP provides a wide variety of built-in string functions. These functions perform various operations such as string transformations, character manipulations, encoding and decoding, and formatting, making string handling s 6 min read Introduction to PHP8 Back in the mid-1990s, PHP started as a Personal Home Page, but now it's known as Hypertext Preprocessor. It's a widely used scripting language that is perfect for web development and can easily be inserted into HTML. Over time, PHP has become super powerful for making dynamic and engaging web apps. 5 min read PHP Defining Constants In a production-level code, it is very important to keep the information as either variables or constants rather than using them explicitly. A PHP constant is nothing but an identifier for a simple value that tends not to change over time(such as the domain name of a website eg. www.geeksforgeeks.or 2 min read How to use PHP in HTML ? In this article, we will use PHP in HTML. There are various methods to integrate PHP and HTML, some of them are discussed below. You can add PHP tags to your HTML Page. You simply need to enclose the PHP code with the PHP starts tag <?php and the PHP end tag ?>. The code wrapped between these 2 min read PHP Syntax PHP, a powerful server-side scripting language used in web development. Itâs simplicity and ease of use makes it an ideal choice for beginners and experienced developers. This article provides an overview of PHP syntax. PHP scripts can be written anywhere in the document within PHP tags along with n 4 min read Like