In this article, let’s learn how to write clean code in PHP. These tips help you to write readable, reusable & refactorable code in PHP.

Use Meaningful & Pronounceable Variable Names

Bad

$ymdstr = date('d-M-Y', strtotime($customer->created_at));

Good

$customerRegisteredDate = date('d-M-Y', strtotime($customer->created_at));

Use Proper & Meaningful Method Names

Bad

public function user($email)
{
    // ...
}

Good

public function getUserDetailsByEmail($email)
{
    // ...
}

Use The Same Vocabulary For Same Type Of Variable

Bad

getUserInfo();
getUserData();
getUserRecord();
getUserProfile();

Good

getUser();

#php

Writing Clean Code in PHP
4.10 GEEK