{"action":"opened","issue":{"url":"https://api.github.com/repos/facebook/hhvm/issues/7599","repository_url":"https://api.github.com/repos/facebook/hhvm","labels_url":"https://api.github.com/repos/facebook/hhvm/issues/7599/labels{/name}","comments_url":"https://api.github.com/repos/facebook/hhvm/issues/7599/comments","events_url":"https://api.github.com/repos/facebook/hhvm/issues/7599/events","html_url":"https://github.com/facebook/hhvm/issues/7599","id":200666046,"number":7599,"title":"Incorrect scope handling enforces bug-prone code.","user":{"login":"rzvc","id":7192924,"avatar_url":"https://avatars.githubusercontent.com/u/7192924?v=3","gravatar_id":"","url":"https://api.github.com/users/rzvc","html_url":"https://github.com/rzvc","followers_url":"https://api.github.com/users/rzvc/followers","following_url":"https://api.github.com/users/rzvc/following{/other_user}","gists_url":"https://api.github.com/users/rzvc/gists{/gist_id}","starred_url":"https://api.github.com/users/rzvc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rzvc/subscriptions","organizations_url":"https://api.github.com/users/rzvc/orgs","repos_url":"https://api.github.com/users/rzvc/repos","events_url":"https://api.github.com/users/rzvc/events{/privacy}","received_events_url":"https://api.github.com/users/rzvc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-13T16:01:32Z","updated_at":"2017-01-13T16:01:32Z","closed_at":null,"body":"### HHVM Version\r\n3.17.1\r\n\r\n### Standalone code, or other way to reproduce the problem\r\n```\r\n$items = [1, 2, 3];\r\n\r\nforeach ($items as &$v)\r\n{\r\n}\r\n\r\nunset($v); // Not allowed, says the variable does not exist in this scope, but it does.\r\n\r\n// Given that we can't unset it, any subsequent use of the variable $v, will overwrite the\r\n// last item it points to.\r\n$v = 'corrupted';\r\n\r\nprint_r($items);\r\n```\r\n\r\nSame thing happens here:\r\n```\r\n$items = [1, 2, 3];\r\n\r\nforeach ($items as $k => $v)\r\n{\r\n\t$z = &$items[$k];\r\n}\r\n\r\nunset($z); // Complains about the undefined variable.\r\n\r\n$z = 'corrupted';\r\n\r\nprint_r($items);\r\n```\r\n\r\n### Expected result\r\nI would expect it to either let me unset it and if I don't, keep track of the variable with its current type, or, it could simply remove it once it goes out of scope, so writing to it would simply initialize a new variable.\r\n\r\n### Actual result\r\nArray\r\n(\r\n    [0] => 1\r\n    [1] => 2\r\n    [2] => corrupted\r\n)"}}
{"actor":{"display_login":"rzvc"}}