PHP Continues to Amaze Me

I don’t know what it is, but I just keep finding new and interesting ways to break PHP. Consider:

$db = new PDO('sqlite::memory:');
$stmt = $db->query('SELECT 1;');
$stmt->setFetchMode(PDO::FETCH_LAZY);
$row = $stmt->fetch();

$class = get_class($row);        // = "PDORow"
var_dump($row instanceof $class) // false!

What the hell. The object isn’t an instance of the class you just told me it was an instance of?

Or this lovely code I ran the other day, which crashes PHP:

class Yippee extends AppendIterator {
    public function __construct() {}
}
$yip = new Yippee;
$yip->rewind();

This will crash PHP with a segfault (on Linux) or a bus error (on OS X). Awesome.

2009/03/11

Participate