Fixed #373 Invalid argument supplied for foreach()
Close #373