Common errors
Warnings such as “Undefined variable” and fatal errors such as TypeError and “Call to undefined function”.
Runs in Zerethon IDE · PHP 8.4
Official PHP documentation ↗
A warning lets the script continue (often with a null value); a fatal error or an uncaught exception stops it. Both name the file and line.
Warning: Undefined variable $x— a typo, or the variable is from outside a function (pass it in, oruseit in a closure).Warning: Undefined array key "name"— the key is missing; use$a["name"] ?? null.Parse error: syntax error, unexpected …— usually a missing;,)or}just before the line shown.Fatal error: Uncaught Error: Call to undefined function area()— the file defining it was notrequired, or the name is misspelled.Fatal error: Uncaught TypeError: …must be of type int, string given— an argument does not match the declared type.Fatal error: Uncaught DivisionByZeroError— dividing by 0 (PHP 8 throws instead of warning).Fatal error: Allowed memory size … exhausted— over the 160 MB limit, often an endless loop that keeps adding to an array.
main.php
<?php
$values = ['10', 'x', '7'];
$total = 0;
foreach ($values as $v) {
if (! is_numeric($v)) {
echo "skipped $v\n";
continue;
}
$total += (int) $v;
}
echo "total: $total\n";
try {
echo intdiv(1, 0);
} catch (DivisionByZeroError $e) {
echo 'caught: ', $e->getMessage(), "\n";
}
Output
skipped x total: 17 caught: Division by zero