PHP Checklist

Some things to consider and remember when programming in modern PHP.

Most of the time, I feel I’m more of a scripter than a programmer. I’m self taught, and although I know OOP, I’m not very fluent in modern PHP (v7+), SOLID principles etc.

In this article, I try to collect things I would like to remember and incorporate when programming in PHP.

It’s a work in progress, so you should not expect it to be comp(rehensive|lete) at any time.

Type hinting

Indicate argument and return types.

function getInt(): int {
    return rand();
function getMaxInt(int $maxint): int {
    return rand(0,$maxint);

Nullable types

You can type hint that null may be accepted/returned by prefixing the type name with a question mark.

function maybeGetInt(): ?int {
    return rand(0,1) ? null : rand();


Exceptions seem like so much extra work, but it makes the code so much more resilient, so I really should use them more, and make my own exception classes.