Fixed a missing null-check and fixed code to be PHP5.4 compliant.