Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Defensive Programming

Defensive programming is a programming approach where the code is written assuming that things can go wrong, even when they shouldn’t, and it should actively guard against incorrect input, unexpected states, or misuse.

<?php

try {
    $number = random_int(0, 10);
} catch (Random\RandomException $e) {
    // This handle cases where no entropy sources are found 
    // This is very rare
}

?>

Documentation

See Also