fixed php 5.4 compatibility. Fixed #1084. Fixed #1069. Fixed #1109