{
    "href": "/post/2008/08/07/exceptional-command-line-php/",
    "relId": "2008/08/07/exceptional-command-line-php",
    "title": "Exceptional command-line PHP",
    "author": "pmjones",
    "markup": "html",
    "tags": [
        {
            "href": "/tag/php/",
            "relId": "php",
            "title": "PHP",
            "author": null,
            "created": null,
            "updated": [],
            "markup": "markdown"
        }
    ],
    "created": "2008-08-08 01:26:34 UTC",
    "updated": [
        "2008-08-08 01:26:34 UTC"
    ],
    "html": "<p><em>(Yes, I know, I've done no blogging in far too long.  I've got a stack of stuff to blog about, but it's all rather heavy.  In the mean time, here's something light.)</em></p>\n<p>When executing code at the command line using <code>php -r</code> <ins datetime=\"2008-08-08T02:27:29+00:00\">and PHP 5.2.5</ins>, be sure not to extend the Exception class.  It will cause a segmentation fault.</p>\n<p>For example, the following causes no trouble at all:</p>\n<pre><code>\nSamurai:~ pmjones$ php -r \"throw new Exception();\"\nPHP Fatal error:  Uncaught exception 'Exception' in Command line code:1\nStack trace:\n#0 {main}\n  thrown in Command line code on line 1\n</code></pre>\n<p>But the next example gives a segmentation fault following a long ... pause ... after the stack trace output:</p>\n<pre><code>\nSamurai:~ pmjones$ php -r \"class Foo extends Exception {} throw new Exception();\"\nFatal error: Uncaught exception 'Exception' in Command line code:1\nStack trace:\n#0 {main}\n  thrown in Command line code on line 1\nSegmentation fault\n</code></pre>\n<p>Note that we didn't even throw the extended Foo exception; we threw the native PHP exception.  The mere presence of the extended class is enough to cause the segfault.</p>\n<p>It took me two evenings to track this down; what you see here is the simplified generic case.  I've entered a bug with the PHP guys <a href=\"http://bugs.php.net/?id=45750\">here</a>.</p>\n<p><strong>Update:</strong> I thought I was running 5.2.6, but I was wrong; this was occurring on PHP 5.2.5.  Note to self: check to make sure you're running the latest version.  :-)</p>\n<p><strong>Update (2008-08-12):</strong> These guys found the problem earlier, too: <a href=\"https://bugs.launchpad.net/ubuntu/+source/php5/+bug/198246\">https://bugs.launchpad.net/ubuntu/+source/php5/+bug/198246</a>.</p>\n"
}
