Back to writing
PHP1 min read

PHP variable name conventions

Whenever someone is new and asks any advice about where to start on their path to learning PHP. In addition to the documentation. Two places I usually recommend are: PHPTheRightWay and PHP-FIG.

With front end frameworks today, such as bootstrap. It's a lot easier to get going with a decent looking site. Unfortunately a clean front-end, does not automatically translate to clean back-end.

When working with a lot of 3rd party software. Efficiency will be left out for this topic. I want to focus solely on variable names and readability.

Lets look at two code samples

Software A:

if($x == $y){
    return z();
}

At a glance, a person looking at this code for the first time will have no idea what $x, $y and $z are doing. As the author. Coming back to this code at a later time. It's also highly likely you will no longer remember the intent.

Software B:

if ($usersRole == $moderator) {
    return moderatorControlPanel();
}

By giving descriptive variable and function name. The intent is more obviously.

These are basic examples, but the point is readability goes a long way.

Thanks for reading.

More from the notebook