General

See Laravel General for general Laravel development information.

Return Types

  • Always specify return types for functions and methods
  • Use void for functions that do not return a value

Typed Properties

  • Always specify types for properties
  • Use mixed when the type is unknown
  • Use ?Type for nullable types

Type Declarations

  • Always specify type declarations for function and method parameters
  • Use mixed when the type is unknown
  • Use ?Type for nullable types

Example

function sum(int $a, int $b): int
{
    return $a + $b;
}

Type Casting

  • Use type casting when necessary
  • Use the (int), (float), (string), (bool), (array), (object), (unset) functions for type casting
  • Do not use the php functions such as intval()

Example

$age = (int) $age;
$price = (float) $price;

Comments

  • Should be avoided where possible
  • Use comments to explain code that is not self-explanatory
  • Comments should be clear, concise, and written in complete sentences
  • Use comments to explain the "why" behind the code, not the "what"

Docblocks

  • Do not use docblocks unless absolutely necessary
  • Do use when documenting the contents of an array or collection
Previous
Home
Next
Naming