Magic Numbers

A magic number is a number that appears in the code, and has no obvious signification.

It is recommended to make the meaning of that number obvious. This is achieved by using constants, class or global, where the name of the constant improves readability.

Magic numbers also applies to other literal values, such as string, float, arrays. Though, they are more difficult to sort out of the code.

Magic numbers are difficult to categorize, when they are very common across different fields. For example, 0, 1, 2, 10 are very common for different tasks, and may need several disambiguations. Others, such as 60, 404,

<?php

foreach($array as $id => $values) {
     // Only displaying 10 values, but couldn't that limit be parametered?
     if ($id > 10) {
             break;
     }

     print $values.PHP_EOL;
}

?>

Documentation

See also What are PHP Magic Numbers, and how to find and remove them, Replace Magic Number with Symbolic Constant

Related packages : povils/phpmnd