PHP#
What can I say? It’s Personal Home Page Tools. That’s what it is good for. Personal home pages where you inject dynamic stuff into static HTML. But not for much more. Unfortunately I am forced to “work” with this language and here I collect some Nice Features (tm) that I found over time.
System Exit#
Scripts should exit with 0 on success and 1 on error. Good enough for most cases as you can put detailed messages on stdout or stderr respectively. See http://tldp.org/LDP/abs/html/exitcodes.html.
PHP:
php <<EOF
<?php
exit("Sure, give me a string and I exit with 0! HAHAHA ha ha...\n");
EOF
echo $?
# prints 0
How a real programming language does it:
python <<EOF
import sys
sys.exit('What's that? A string? Are you stupid?')
EOF
echo $?
# prints 1
Here comes the funny part. PDO replaces the Exception code with a string [1] and Symfony 1.4 has the following code in its cli.php:
// ...
catch (Exception $e)
{
if (!isset($application))
{
throw $e;
}
$application->renderException($e);
$statusCode = $e->getCode();
exit(is_numeric($statusCode) && $statusCode ? $statusCode : 1);
}
So any task that dies because of an SQL Error returns with exit code 0. Good luck finding this in your CI jobs.