diff options
Diffstat (limited to 'Zend/tests/use_const')
-rw-r--r-- | Zend/tests/use_const/alias.phpt | 26 | ||||
-rw-r--r-- | Zend/tests/use_const/basic.phpt | 22 | ||||
-rw-r--r-- | Zend/tests/use_const/case_sensivity.phpt | 12 | ||||
-rw-r--r-- | Zend/tests/use_const/conflicting_use.phpt | 21 | ||||
-rw-r--r-- | Zend/tests/use_const/conflicting_use_alias.phpt | 18 | ||||
-rw-r--r-- | Zend/tests/use_const/define_imported.phpt | 14 | ||||
-rw-r--r-- | Zend/tests/use_const/define_imported_before.phpt | 18 | ||||
-rw-r--r-- | Zend/tests/use_const/includes/foo_bar.php | 5 | ||||
-rw-r--r-- | Zend/tests/use_const/includes/foo_php_version.php | 5 | ||||
-rw-r--r-- | Zend/tests/use_const/includes/global_bar.php | 3 | ||||
-rw-r--r-- | Zend/tests/use_const/includes/global_baz.php | 3 | ||||
-rw-r--r-- | Zend/tests/use_const/no_global_fallback.phpt | 14 | ||||
-rw-r--r-- | Zend/tests/use_const/self_parent.phpt | 12 | ||||
-rw-r--r-- | Zend/tests/use_const/shadow_core.phpt | 16 | ||||
-rw-r--r-- | Zend/tests/use_const/shadow_global.phpt | 25 |
15 files changed, 214 insertions, 0 deletions
diff --git a/Zend/tests/use_const/alias.phpt b/Zend/tests/use_const/alias.phpt new file mode 100644 index 0000000000..f179393006 --- /dev/null +++ b/Zend/tests/use_const/alias.phpt @@ -0,0 +1,26 @@ +--TEST-- +aliasing imported constants to resolve naming conflicts +--FILE-- +<?php + +namespace foo { + const baz = 42; +} + +namespace bar { + const baz = 43; +} + +namespace { + use const foo\baz as foo_baz, + bar\baz as bar_baz; + var_dump(foo_baz); + var_dump(bar_baz); + echo "Done\n"; +} + +?> +--EXPECT-- +int(42) +int(43) +Done diff --git a/Zend/tests/use_const/basic.phpt b/Zend/tests/use_const/basic.phpt new file mode 100644 index 0000000000..6eaed7f27d --- /dev/null +++ b/Zend/tests/use_const/basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +import namespaced constant +--FILE-- +<?php + +namespace foo\bar { + const baz = 42; + const qux = 43; +} + +namespace { + use const foo\bar\baz, foo\bar\qux; + var_dump(baz); + var_dump(qux); + echo "Done\n"; +} + +?> +--EXPECT-- +int(42) +int(43) +Done diff --git a/Zend/tests/use_const/case_sensivity.phpt b/Zend/tests/use_const/case_sensivity.phpt new file mode 100644 index 0000000000..1977daa93b --- /dev/null +++ b/Zend/tests/use_const/case_sensivity.phpt @@ -0,0 +1,12 @@ +--TEST-- +importing const with same name but different case +--FILE-- +<?php + +namespace { + use const foo\bar; + use const foo\BAR; +} + +?> +--EXPECT-- diff --git a/Zend/tests/use_const/conflicting_use.phpt b/Zend/tests/use_const/conflicting_use.phpt new file mode 100644 index 0000000000..3b3c4b3262 --- /dev/null +++ b/Zend/tests/use_const/conflicting_use.phpt @@ -0,0 +1,21 @@ +--TEST-- +use const statements with conflicting names +--FILE-- +<?php + +namespace foo { + const baz = 42; +} + +namespace bar { + const baz = 42; +} + +namespace { + use const foo\baz, bar\baz; + echo "Done\n"; +} + +?> +--EXPECTF-- +Fatal error: Cannot use const bar\baz as baz because the name is already in use in %s on line %d diff --git a/Zend/tests/use_const/conflicting_use_alias.phpt b/Zend/tests/use_const/conflicting_use_alias.phpt new file mode 100644 index 0000000000..8b563a4ca9 --- /dev/null +++ b/Zend/tests/use_const/conflicting_use_alias.phpt @@ -0,0 +1,18 @@ +--TEST-- +use and use const with the same alias +--FILE-- +<?php + +namespace { + const foo = 'foo'; +} + +namespace x { + use foo as bar; + use const foo as bar; + var_dump(bar); +} + +?> +--EXPECT-- +string(3) "foo" diff --git a/Zend/tests/use_const/define_imported.phpt b/Zend/tests/use_const/define_imported.phpt new file mode 100644 index 0000000000..5eb44be64a --- /dev/null +++ b/Zend/tests/use_const/define_imported.phpt @@ -0,0 +1,14 @@ +--TEST-- +defining const with same name as imported should fail +--FILE-- +<?php + +namespace { + use const foo\bar; + + const bar = 42; +} + +?> +--EXPECTF-- +Fatal error: Cannot declare const bar because the name is already in use in %s on line %d diff --git a/Zend/tests/use_const/define_imported_before.phpt b/Zend/tests/use_const/define_imported_before.phpt new file mode 100644 index 0000000000..f674ce81e8 --- /dev/null +++ b/Zend/tests/use_const/define_imported_before.phpt @@ -0,0 +1,18 @@ +--TEST-- +using const with same name as defined should fail +--FILE-- +<?php + +namespace { + const bar = 42; + + use const foo\bar; +} + +namespace { + echo "Done"; +} + +?> +--EXPECTF-- +Fatal error: Cannot use const foo\bar as bar because the name is already in use in %s on line %d diff --git a/Zend/tests/use_const/includes/foo_bar.php b/Zend/tests/use_const/includes/foo_bar.php new file mode 100644 index 0000000000..90ed451f36 --- /dev/null +++ b/Zend/tests/use_const/includes/foo_bar.php @@ -0,0 +1,5 @@ +<?php + +namespace foo; + +const bar = 'local bar'; diff --git a/Zend/tests/use_const/includes/foo_php_version.php b/Zend/tests/use_const/includes/foo_php_version.php new file mode 100644 index 0000000000..08f9fd150e --- /dev/null +++ b/Zend/tests/use_const/includes/foo_php_version.php @@ -0,0 +1,5 @@ +<?php + +namespace foo; + +const PHP_VERSION = 42; diff --git a/Zend/tests/use_const/includes/global_bar.php b/Zend/tests/use_const/includes/global_bar.php new file mode 100644 index 0000000000..609d17b7b5 --- /dev/null +++ b/Zend/tests/use_const/includes/global_bar.php @@ -0,0 +1,3 @@ +<?php + +const bar = 'global bar'; diff --git a/Zend/tests/use_const/includes/global_baz.php b/Zend/tests/use_const/includes/global_baz.php new file mode 100644 index 0000000000..8b6fba97b3 --- /dev/null +++ b/Zend/tests/use_const/includes/global_baz.php @@ -0,0 +1,3 @@ +<?php + +const baz = NULL; diff --git a/Zend/tests/use_const/no_global_fallback.phpt b/Zend/tests/use_const/no_global_fallback.phpt new file mode 100644 index 0000000000..a128f353ed --- /dev/null +++ b/Zend/tests/use_const/no_global_fallback.phpt @@ -0,0 +1,14 @@ +--TEST-- +non-existent imported constants should not be looked up in the global table +--FILE-- +<?php + +require 'includes/global_baz.php'; + +use const foo\bar\baz; +var_dump(baz); + +?> +--EXPECTF-- +Notice: Use of undefined constant baz - assumed 'baz' in %s on line %d +string(3) "baz" diff --git a/Zend/tests/use_const/self_parent.phpt b/Zend/tests/use_const/self_parent.phpt new file mode 100644 index 0000000000..b71f2ecc81 --- /dev/null +++ b/Zend/tests/use_const/self_parent.phpt @@ -0,0 +1,12 @@ +--TEST-- +Allow self and parent in use const statement +--FILE-- +<?php + +namespace { + use const self as foo; + use const parent as bar; +} + +?> +--EXPECT-- diff --git a/Zend/tests/use_const/shadow_core.phpt b/Zend/tests/use_const/shadow_core.phpt new file mode 100644 index 0000000000..7d8bcbd189 --- /dev/null +++ b/Zend/tests/use_const/shadow_core.phpt @@ -0,0 +1,16 @@ +--TEST-- +shadowing a global core constant with a local version +--FILE-- +<?php + +require 'includes/foo_php_version.php'; + +use const foo\PHP_VERSION; + +var_dump(PHP_VERSION); +echo "Done\n"; + +?> +--EXPECTF-- +int(42) +Done diff --git a/Zend/tests/use_const/shadow_global.phpt b/Zend/tests/use_const/shadow_global.phpt new file mode 100644 index 0000000000..930cc9f0b8 --- /dev/null +++ b/Zend/tests/use_const/shadow_global.phpt @@ -0,0 +1,25 @@ +--TEST-- +shadowing a global constant with a local version +--FILE-- +<?php + +namespace { + require 'includes/global_bar.php'; + require 'includes/foo_bar.php'; +} + +namespace { + var_dump(bar); +} + +namespace { + use const foo\bar; + var_dump(bar); + echo "Done\n"; +} + +?> +--EXPECT-- +string(10) "global bar" +string(9) "local bar" +Done |