diff options
Diffstat (limited to 'Zend/tests/restrict_globals')
16 files changed, 215 insertions, 0 deletions
diff --git a/Zend/tests/restrict_globals/globals_in_globals.phpt b/Zend/tests/restrict_globals/globals_in_globals.phpt new file mode 100644 index 0000000000..fbb811708c --- /dev/null +++ b/Zend/tests/restrict_globals/globals_in_globals.phpt @@ -0,0 +1,11 @@ +--TEST-- +$GLOBALS no longer contains 'GLOBALS' +--FILE-- +<?php + +$g = $GLOBALS; +var_dump(isset($g['GLOBALS'])); + +?> +--EXPECT-- +bool(false) diff --git a/Zend/tests/restrict_globals/invalid_append.phpt b/Zend/tests/restrict_globals/invalid_append.phpt new file mode 100644 index 0000000000..8e8b99fb9b --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_append.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot append to $GLOBALS +--FILE-- +<?php + +$GLOBALS[] = 1; + +?> +--EXPECTF-- +Fatal error: Cannot append to $GLOBALS in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_append_isset.phpt b/Zend/tests/restrict_globals/invalid_append_isset.phpt new file mode 100644 index 0000000000..6cb57351e7 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_append_isset.phpt @@ -0,0 +1,8 @@ +--TEST-- +Cannot append to $GLOBALS in isset() +--FILE-- +<?php +isset($GLOBALS[]); +?> +--EXPECTF-- +Fatal error: Cannot use [] for reading in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_append_unset.phpt b/Zend/tests/restrict_globals/invalid_append_unset.phpt new file mode 100644 index 0000000000..b7c06179c7 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_append_unset.phpt @@ -0,0 +1,8 @@ +--TEST-- +Cannot append to $GLOBALS in unset() +--FILE-- +<?php +unset($GLOBALS[]); +?> +--EXPECTF-- +Fatal error: Cannot use [] for unsetting in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_assign.phpt b/Zend/tests/restrict_globals/invalid_assign.phpt new file mode 100644 index 0000000000..c42cc9e1f9 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_assign.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot assign to $GLOBALS +--FILE-- +<?php + +$GLOBALS = []; + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_assign_list.phpt b/Zend/tests/restrict_globals/invalid_assign_list.phpt new file mode 100644 index 0000000000..8fc3e524a9 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_assign_list.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot list-assign to $GLOBALS +--FILE-- +<?php + +list($GLOBALS) = [1]; + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_assign_list_ref.phpt b/Zend/tests/restrict_globals/invalid_assign_list_ref.phpt new file mode 100644 index 0000000000..594a308ea1 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_assign_list_ref.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot list-assign to $GLOBALS (by-ref) +--FILE-- +<?php + +list(&$GLOBALS) = [1]; + +?> +--EXPECTF-- +Fatal error: Cannot assign reference to non referencable value in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_assign_op.phpt b/Zend/tests/restrict_globals/invalid_assign_op.phpt new file mode 100644 index 0000000000..a9b36853ea --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_assign_op.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot compound assign to $GLOBALS +--FILE-- +<?php + +$GLOBALS += []; + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_assign_ref_lhs.phpt b/Zend/tests/restrict_globals/invalid_assign_ref_lhs.phpt new file mode 100644 index 0000000000..b14c167646 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_assign_ref_lhs.phpt @@ -0,0 +1,11 @@ +--TEST-- +Cannot by-ref assign to $GLOBALS (LHS) +--FILE-- +<?php + +$var = []; +$GLOBALS =& $var; + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_assign_ref_rhs.phpt b/Zend/tests/restrict_globals/invalid_assign_ref_rhs.phpt new file mode 100644 index 0000000000..3cdab0f9c9 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_assign_ref_rhs.phpt @@ -0,0 +1,11 @@ +--TEST-- +Cannot by-ref assign to $GLOBALS (RHS) +--FILE-- +<?php + +$var = []; +$var =& $GLOBALS; + +?> +--EXPECTF-- +Fatal error: Cannot acquire reference to $GLOBALS in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_foreach.phpt b/Zend/tests/restrict_globals/invalid_foreach.phpt new file mode 100644 index 0000000000..0e7c74881a --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_foreach.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot use $GLOBALS as foreach result variable +--FILE-- +<?php + +foreach ([1] as $GLOBALS) {} + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_foreach_ref.phpt b/Zend/tests/restrict_globals/invalid_foreach_ref.phpt new file mode 100644 index 0000000000..2c355c09ae --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_foreach_ref.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot use $GLOBALS as foreach result variable (by-ref) +--FILE-- +<?php + +foreach ([1] as &$GLOBALS) {} + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/invalid_pass_by_ref.phpt b/Zend/tests/restrict_globals/invalid_pass_by_ref.phpt new file mode 100644 index 0000000000..a0145a0624 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_pass_by_ref.phpt @@ -0,0 +1,23 @@ +--TEST-- +$GLOBALS cannot be passed by reference (runtime error) +--FILE-- +<?php + +function by_ref(&$ref) {} +try { + by_ref($GLOBALS); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +try { + by_ref2($GLOBALS); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +function by_ref2(&$ref) {} + +?> +--EXPECT-- +by_ref(): Argument #1 ($ref) cannot be passed by reference +by_ref2(): Argument #1 ($ref) cannot be passed by reference diff --git a/Zend/tests/restrict_globals/invalid_unset.phpt b/Zend/tests/restrict_globals/invalid_unset.phpt new file mode 100644 index 0000000000..781388b9b2 --- /dev/null +++ b/Zend/tests/restrict_globals/invalid_unset.phpt @@ -0,0 +1,10 @@ +--TEST-- +Cannot unset $GLOBALS +--FILE-- +<?php + +unset($GLOBALS); + +?> +--EXPECTF-- +Fatal error: $GLOBALS can only be modified using the $GLOBALS[$name] = $value syntax in %s on line %d diff --git a/Zend/tests/restrict_globals/key_canonicalization.phpt b/Zend/tests/restrict_globals/key_canonicalization.phpt new file mode 100644 index 0000000000..66d9a29a92 --- /dev/null +++ b/Zend/tests/restrict_globals/key_canonicalization.phpt @@ -0,0 +1,11 @@ +--TEST-- +$GLOBALS should have canonicalized keys +--FILE-- +<?php + +${1} = 42; +var_dump($GLOBALS[1]); + +?> +--EXPECT-- +int(42) diff --git a/Zend/tests/restrict_globals/valid.phpt b/Zend/tests/restrict_globals/valid.phpt new file mode 100644 index 0000000000..b99bbe402f --- /dev/null +++ b/Zend/tests/restrict_globals/valid.phpt @@ -0,0 +1,52 @@ +--TEST-- +Supported operations on $GLOBALS +--FILE-- +<?php + +function test() { + var_dump($GLOBALS['x']); + $GLOBALS['x'] = 1; + var_dump($GLOBALS['x']); + $GLOBALS['x']++; + var_dump($GLOBALS['x']); + $GLOBALS['x'] += 2; + var_dump($GLOBALS['x']); + unset($GLOBALS['y']); + var_dump(isset($GLOBALS['x'])); + var_dump(isset($GLOBALS['y'])); + $GLOBALS['z'][] = 1; +} + +$y = 1; +test(); +var_dump($x, $y, $z); + +$ref = 1; +$GLOBALS['z'] =& $ref; +$ref++; +var_dump($z); + +$x = 1; +$ref2 =& $GLOBALS['x']; +$ref2++; +var_dump($x); + +?> +--EXPECTF-- +Warning: Undefined global variable $x in %s on line %d +NULL +int(1) +int(2) +int(4) +bool(true) +bool(false) + +Warning: Undefined variable $y in %s on line %d +int(4) +NULL +array(1) { + [0]=> + int(1) +} +int(2) +int(2) |