5. PHP Specific Standards

PHP Tags:

// Good
<?php

// or for short
<?= $variable ?>

// Bad
<?

Strings:

// Good
$name = 'John'; 
$greeting = "Hello, {$name}";  

// Bad
$name = "John"; 
$greeting = 'Hello, ' . $name; 

Arrays:

// Good
$array = [1, 2, 3];  

// Bad
$array = array(1, 2, 3); 

Control Structures:

// Good
if ($condition) {     
    // do something 
}  

// Bad
if ($condition)     // do something

if($condition)
    // do something

//-----------------------------------------------------------------------------

// if you are using this in the view it is good, 
//but if you are using it from the controller or PHP logic alone it is not good
if($condition):
    // do something
endif;

Error Handling:

// Good
try {     
    // code that may throw an exception 
} catch (Exception $e) {     
    // handle exception 
}  

// Bad
if (!$result) {     
    die('Error!'); 
} 

Namespaces and Use Statements:

// Good
namespace App\Controllers;  

use App\Controller\SomeController;  

// Bad
namespace App\Controllers;  

include_once '../Controller/SomeController.php';