1.1 Variables:

  • Use camelCase for variable names.
  • Variable names should be descriptive and concise.
  • Avoid abbreviations unless widely recognized.


$userName = 'John';
$totalAmount = 100;


1.2 Functions and Methods:

  • Use camelCase for function and method names.
  • Function and method names should clearly express their purpose.
  • Methods should start with a verb when possible.



function calculateTotalAmount($prices)
{
    // Logic here 
}


1.3 Classes:

  • Use PascalCase for class names.
  • Class names should be nouns and describe the entity or the functionality.


class UserController 
{ 
    // Class definition
}


1.4 Constants:

  • Use UPPER_CASE with underscores (screaming snake case) for constants.
  • Constants should be descriptive and represent fixed values.



define('MAX_RETRY_ATTEMPTS', 5); 
const DEFAULT_TIMEOUT = 30;


1.5 Interfaces:

  • Use PascalCase with the suffix Interface.
  • Interfaces should describe behavior and represent contracts.


interface CacheInterface 
{ 
    public function get(string $key): int; 
    public function set(string $key, string $value); 
}


1.6 Abstract classes

  • Use PascalCase with the prefix Abstract.


abstract class AbstractJob
{
    abstract public function getName(): string;
    // Other logic here
}


1.7 Namespaces:

  • Use PascalCase for namespaces.
  • Namespace names should map to the directory structure.


namespace App\Controllers;





PSR-12: Extended Coding Style

Link to PSR-12 article: https://www.php-fig.org/psr/psr-12/

Principles: