Skip to content
Permalink
Browse files

Reject use of superglobals in strict mode

Summary: We should not permit the use of super-globals in strict mode. This used to be handled in the naming phase, but since D7763002 we relied on the typing phase to catch undefined locals.

Reviewed By: kmeht, billf

Differential Revision: D13712575

fbshipit-source-id: 165669fe28f961292463ce92b3e198acc1570a91
  • Loading branch information...
andrewjkennedy authored and hhvm-bot committed Jan 19, 2019
1 parent 80c60cd commit 48606cc75a4d2e7a7c77a46992c5732ac199e0f8
@@ -1054,7 +1054,7 @@ let get_locals env =
let get_local_in_ctx env ?error_if_undef_at_pos:p x ctx =
let not_found_is_ok x =
let x = LID.to_string x in
SG.is_superglobal x ||
SG.is_superglobal x && not (is_strict env) ||
SSet.mem x env.lenv.fake_members.valid in
let error_if_pos_provided posopt =
match posopt with
@@ -0,0 +1,6 @@
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function foo():void {
$GLOBALS['bar'] = 3;
}
@@ -0,0 +1,2 @@
File "badglobal.php", line 5, characters 3-10:
Variable $GLOBALS is undefined, or there exists at least one control flow path reaching this point which does not define $GLOBALS. (Naming[2050])
@@ -1 +1,2 @@
No errors
File "superglobals.php", line 4, characters 8-15:
Variable $_SERVER is undefined, or there exists at least one control flow path reaching this point which does not define $_SERVER. (Naming[2050])

0 comments on commit 48606cc

Please sign in to comment.
You can’t perform that action at this time.