fixed build on php <= 5.3.6
added debug checks