Fix issue #9589 and some == null comparisons

This should fix issue #9589. Also replace == null to === null  and phpDoc for clear code.