Do you need to call PDOStatement::closeCursor when you’re done with the statement?

The answer is no, so long as you’re not preparing to execute the statement again. I figured this out by looking at the code for PDOStatement::closeCursor and the MySQL implementation. Seems to me that all the freeing necessary is done in the destructor so if you’re not planning to use the statement again it seems to me that you can safely omit the call to PDOStatement::closeCursor(). On the other hand if you are going to reuse the statement calling closeCursor seems like it’s a pretty important thing to do. It would be nice if PDOStatement::fetchAll() called closeCursor() for us, but I don’t think it does.

PHP finally blocks not run on exit

I confirmed with the following code that if you call ‘exit’ withing a ‘try’ block the ‘finally’ block does *not* execute. That’s probably what you would expect. But now we know.

register_shutdown_function( 'handle_shutdown' );

try {

  exit;

}
catch ( Exception $ex ) {

  echo "caught...\n";

}
finally {

  echo "finally...\n";

}

function handle_shutdown() {

  echo "shutdown...\n";

}