Add some safety nets

If only all PHP code was well-behaved...