Make JEventDispatcher compatible with HHVM

According to HHVM inconsistencies guildline, "Under Zend PHP, foreach by value will modify the array's internal cursor under certain circumstances. Under HipHop VM, foreach by value will never modify the array's internal cursor.

Moving end() from above key() function to below it also make the code easier to understand as the behavior of foreach with array cursor is complicated to understand.
Merge pull request #3199 from chalet16/patch-1

Make JEventDispatcher compatible with HHVM