PHP Sadness

Some error conditions are simply uncatchable

There are some error conditions which should be catchable but simply aren't:

$ cat fatals.php
<?php

function error_handler($errno, $errstr, $errfile, $errline) {
  $a = func_get_args();
  var_dump($a);
}

set_error_handler("error_handler");

try {
  $x = new NonexistantClass();
} catch (Exception $e) {
  var_dump($e->getMessage());
}

echo "Don't worry, everything is still fine!\n";


$ php fatals.php

Fatal error: Class 'NonexistantClass' not found in...

It's not that I'm sad that this isn't an php Exception, or that I'm confused about the difference between that and php error_reporting / php set_error_handler / etc. It's that I'm sad that I have no way of handling this situation other than running another PHP process and noticing when it dies.

Significance: Missing Features

Language features make developers' lives easier. Often, language features are not complex for the language designers to implement (barring unnecessary complications in the internals), but can save developers hours of time. Missing language features are disrespectful to developers and encourage dirty hacks, "clever" solutions, and kludgy workarounds to achieve the desired functionality.

Significance: Implications for Internals

The mere presence of this issue tends to imply some fatal flaw or unnecessary complexity at the most basic levels of the language. For example, an overly complex parser might be trying to compensate for missing functionality in the interpreter by incorrectly (and misleadingly) validating code at the syntax level, or messages without details could indicate that the internal design prohibits access to values where they should be reachable in a sane implementation.