Always check variable type before using readdir to avoid surprises
more is_resource checks before readdir
Merge pull request #4719 from owncloud/port_4701_master

Always check variable type before using readdir to avoid surprises