2 Functions
LogMANOriginal edited this page 2018-11-05 13:28:10 +01:00

Parameters with default values must appear last in functions

It is considered good practice to make parameters with default values last in function declarations.

Example

Bad

function showTitle($duration = 60000, $title) { ... }

Good

function showTitle($title, $duration = 60000) { ... }

Reference: PEAR.Functions.ValidDefaultValue

Calling functions

Function calls must follow a few rules in order to maintain readability throughout the project:

Do not add whitespace before the opening parenthesis

Example

Bad

$result = my_function ($param);

Good

$result = my_function($param);

Do not add whitespace after the opening parenthesis

Example

Bad

$result = my_function( $param);

Good

$result = my_function($param);

Do not add a space before the closing parenthesis

Example

Bad

$result = my_function($param );

Good

$result = my_function($param);

Do not add a space before a comma

Example

Bad

$result = my_function($param1 ,$param2);

Good

$result = my_function($param1, $param2);

Add a space after a comma

Example

Bad

$result = my_function($param1,$param2);

Good

$result = my_function($param1, $param2);

Reference: Generic.Functions.FunctionCallArgumentSpacing

Do not add spaces after opening or before closing bracket

Parenthesis must tightly enclose parameters.

Example

Bad

if( $condition ) { ... }

Good

if($condition) { ... }

Reference: PSR2.ControlStructures.ControlStructureSpacing