0% found this document useful (0 votes)
8 views5 pages

PHP Coding Style and Git Guide

Uploaded by

priya h.p
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

PHP Coding Style and Git Guide

Uploaded by

priya h.p
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Basic Coding Style Guide:

[Link]:
All PHP files MUST use the Unix LF (linefeed) line ending.
All PHP files MUST end with a single blank line.

2. Lines:
Lines SHOULD NOT be longer than 80 characters; lines longer than that
SHOULD be split into multiple subsequent lines of no more than 80 characters
each.
There MUST NOT be trailing whitespace at the end of non-blank lines.

[Link]
Code MUST use an indent of 4 spaces and MUST NOT use tabs for indenting.

[Link] and True/False/Null


PHP keywords MUST be in lower case.
The PHP constants true, false, and null MUST be in lower case.

[Link] and Use Declarations


When present, there MUST be one blank line after the namespace declaration.
When present, all use declarations MUST go after the namespace declaration.
There MUST be one use keyword per declaration
There MUST be one blank line after the use block.

[Link] Structures
There MUST be one space after the control structure keyword
There MUST NOT be a space after the opening parenthesis
There MUST NOT be a space before the closing parenthesis
There MUST be one space between the closing parenthesis and the opening
brace
The structure body MUST be indented once
The closing brace MUST be on the next line after the body
7. Extends and Implements
The extends and implements keywords MUST be declared on the same line as
the class name.
The opening brace for the class MUST go on its own line; the closing brace for
the class MUST go on the next line after the body.
Opening braces MUST be on their own line and MUST NOT be preceded or
followed by a blank line.
Closing braces MUST be on their own line and MUST NOT be preceded by a
blank line.

[Link] and Constants


Visibility MUST be declared on all properties and constants.
The var keyword MUST NOT be used to declare a property.
There MUST be a space between type declaration and property name.

[Link] and Functions


Visibility MUST be declared on all methods.
The opening brace MUST go on its own line, and the closing brace MUST go on
the next line following the body.
There MUST NOT be a space after the opening parenthesis, and there MUST
NOT be a space before the closing parenthesis.

[Link] and Function Arguments


In the argument list, there MUST NOT be a space before each comma, and
there MUST be one space after each comma
New Features:
[Link] nullsafe operator

[Link] arguments

[Link] expression

4. Constructor property promotion


class Money

public function __construct(

public Currency $currency,


public int $amount,

) {}

New PHP Functions

[Link] str_contains() function

Some may argue it’s long overdue, but essentially we no longer have to rely on
strops() to know whether there’s another string within a string.

[Link] str_starts_with() and str_ends_with() functions

These two functions are long overdue and are now part of the core.

[Link] fdiv() function

The new fdiv() function has similar ability as the fmod() and intdiv() functions,
that allows for division by 0.
Instead of getting errors, you’ll get INF, -INF, or NAN, depending on the
scenario.

4.get_debug_type() function

The new get_debug_type function always returns the true native type of
variables. It returns a return native type names, e.g., int rather than integer,
double instead of float.

Git:

git init
git remote add origin [Link]
git fetch && git checkout develop
git add file_name
git commit -m “SQ1ASM-1 : Commit msg”
git config --global [Link] "FIRST_NAME LAST_NAME"
For code Review create PR : From develop -> master branch

Common questions

Powered by AI

New PHP functions like str_contains(), str_starts_with(), and str_ends_with() greatly improve string manipulation by providing built-in functionality for common string operations. These reduce reliance on workarounds, simplifying code and minimizing bugs, thus improving coding efficiency .

The fdiv() function allows division by zero scenarios without causing errors, returning INF, -INF, or NAN instead. This improves error handling and numerical stability compared to traditional methods that would throw exceptions or errors .

PHP files must use the Unix LF (linefeed) line ending and end with a single blank line. Lines should not exceed 80 characters, and longer lines must be split. Indentation must use 4 spaces, not tabs. Additionally, trailing whitespace at the end of non-blank lines is prohibited .

Not allowing spaces around parentheses in function declarations and calls maintains strict syntactic uniformity, which prevents misinterpretation errors and enforces a higher level of precision in code writing and reading. This ensures a cleaner codebase and aids automated parsing systems .

Match expressions offer a more concise alternative to switch statements, allowing for fewer lines of code and eliminating the need for break statements. They also support clearer expression syntax with strict type checking, thereby reducing potential runtime errors .

The 'extends' and 'implements' keywords must be on the same line as the class name, ensuring readability and consistency. Opening braces for the class should be on their own line, and closing braces on the next line after the body, which prevents confusion in code structure .

Declaring visibility on methods and properties ensures clarity in access levels, enhancing code readability and maintainability, and enforcing encapsulation principles. This is crucial for understanding what parts of the code can be accessed or modified from outside classes .

Control structures in PHP must have one space after the keyword, no spaces around parenthesis, and a space between the closing parenthesis and opening brace. The structure body must be indented once, and closing braces placed on the line following the body. These rules enhance clarity by maintaining a consistent structure .

The get_debug_type() function provides precise native type names, such as 'int' or 'double,' rather than verbose descriptions. It improves debugging by offering clear, concise information about variable types, reducing the risk of errors due to type mismatches .

The nullsafe operator '?->' prevents null reference errors by short-circuiting evaluations. This is crucial for handling objects that might be null dynamically, reducing the need for nested if-checks and enhancing code readability and reliability .

You might also like