Add support for non-scalar foreach keys

This is just a preliminary patch for the https://wiki.php.net/rfc/foreach-non-scalar-keys RFC.