diff options
Diffstat (limited to 'Zend/tests/use_function')
19 files changed, 316 insertions, 0 deletions
diff --git a/Zend/tests/use_function/alias.phpt b/Zend/tests/use_function/alias.phpt new file mode 100644 index 0000000000..5f7e97fff8 --- /dev/null +++ b/Zend/tests/use_function/alias.phpt @@ -0,0 +1,30 @@ +--TEST-- +aliasing imported functions to resolve naming conflicts +--FILE-- +<?php + +namespace foo { + function baz() { + return 'foo.baz'; + } +} + +namespace bar { + function baz() { + return 'bar.baz'; + } +} + +namespace { + use function foo\baz as foo_baz, + bar\baz as bar_baz; + var_dump(foo_baz()); + var_dump(bar_baz()); + echo "Done\n"; +} + +?> +--EXPECT-- +string(7) "foo.baz" +string(7) "bar.baz" +Done diff --git a/Zend/tests/use_function/basic.phpt b/Zend/tests/use_function/basic.phpt new file mode 100644 index 0000000000..513a96620c --- /dev/null +++ b/Zend/tests/use_function/basic.phpt @@ -0,0 +1,26 @@ +--TEST-- +import namespaced function +--FILE-- +<?php + +namespace foo\bar { + function baz() { + return 'foo.bar.baz'; + } + function qux() { + return baz(); + } +} + +namespace { + use function foo\bar\baz, foo\bar\qux; + var_dump(baz()); + var_dump(qux()); + echo "Done\n"; +} + +?> +--EXPECT-- +string(11) "foo.bar.baz" +string(11) "foo.bar.baz" +Done diff --git a/Zend/tests/use_function/case_insensivity.phpt b/Zend/tests/use_function/case_insensivity.phpt new file mode 100644 index 0000000000..ba6e3a7e4b --- /dev/null +++ b/Zend/tests/use_function/case_insensivity.phpt @@ -0,0 +1,13 @@ +--TEST-- +importing function with same name but different case should fail +--FILE-- +<?php + +namespace { + use function foo\bar; + use function foo\BAR; +} + +?> +--EXPECTF-- +Fatal error: Cannot use function foo\BAR as BAR because the name is already in use in %s on line %d diff --git a/Zend/tests/use_function/conditional_function_declaration.phpt b/Zend/tests/use_function/conditional_function_declaration.phpt new file mode 100644 index 0000000000..ccfb96103a --- /dev/null +++ b/Zend/tests/use_function/conditional_function_declaration.phpt @@ -0,0 +1,17 @@ +--TEST-- +function that is conditionally defined at runtime should not cause compiler error +--FILE-- +<?php + +if (0) { + function foo() { + } +} + +use function bar\foo; + +echo "Done"; + +?> +--EXPECT-- +Done diff --git a/Zend/tests/use_function/conflicting_use.phpt b/Zend/tests/use_function/conflicting_use.phpt new file mode 100644 index 0000000000..0221fbdebb --- /dev/null +++ b/Zend/tests/use_function/conflicting_use.phpt @@ -0,0 +1,25 @@ +--TEST-- +use function statements with conflicting names +--FILE-- +<?php + +namespace foo { + function baz() { + return 'foo.baz'; + } +} + +namespace bar { + function baz() { + return 'bar.baz'; + } +} + +namespace { + use function foo\baz, bar\baz; + echo "Done\n"; +} + +?> +--EXPECTF-- +Fatal error: Cannot use function bar\baz as baz because the name is already in use in %s on line %d diff --git a/Zend/tests/use_function/conflicting_use_alias.phpt b/Zend/tests/use_function/conflicting_use_alias.phpt new file mode 100644 index 0000000000..2870512014 --- /dev/null +++ b/Zend/tests/use_function/conflicting_use_alias.phpt @@ -0,0 +1,20 @@ +--TEST-- +use and use function with the same alias +--FILE-- +<?php + +namespace { + function foo() { + return 'foo'; + } +} + +namespace x { + use foo as bar; + use function foo as bar; + var_dump(bar()); +} + +?> +--EXPECT-- +string(3) "foo" diff --git a/Zend/tests/use_function/conflicting_use_const_alias.phpt b/Zend/tests/use_function/conflicting_use_const_alias.phpt new file mode 100644 index 0000000000..2e0faf0da2 --- /dev/null +++ b/Zend/tests/use_function/conflicting_use_const_alias.phpt @@ -0,0 +1,23 @@ +--TEST-- +use const and use function with the same alias +--FILE-- +<?php + +namespace { + const foo = 'foo.const'; + function foo() { + return 'foo.function'; + } +} + +namespace x { + use const foo as bar; + use function foo as bar; + var_dump(bar); + var_dump(bar()); +} + +?> +--EXPECT-- +string(9) "foo.const" +string(12) "foo.function" diff --git a/Zend/tests/use_function/define_imported.phpt b/Zend/tests/use_function/define_imported.phpt new file mode 100644 index 0000000000..c542a4d549 --- /dev/null +++ b/Zend/tests/use_function/define_imported.phpt @@ -0,0 +1,14 @@ +--TEST-- +defining function with same name as imported should fail +--FILE-- +<?php + +namespace { + use function foo\bar; + + function bar() {} +} + +?> +--EXPECTF-- +Fatal error: Cannot declare function bar because the name is already in use in %s on line %d diff --git a/Zend/tests/use_function/define_imported_before.phpt b/Zend/tests/use_function/define_imported_before.phpt new file mode 100644 index 0000000000..91974e0783 --- /dev/null +++ b/Zend/tests/use_function/define_imported_before.phpt @@ -0,0 +1,18 @@ +--TEST-- +using function with same name as defined should fail +--FILE-- +<?php + +namespace { + function bar() {} + + use function foo\bar; +} + +namespace { + echo "Done"; +} + +?> +--EXPECTF-- +Fatal error: Cannot use function foo\bar as bar because the name is already in use in %s on line %d diff --git a/Zend/tests/use_function/ignore_constants.phpt b/Zend/tests/use_function/ignore_constants.phpt new file mode 100644 index 0000000000..c50ff7357a --- /dev/null +++ b/Zend/tests/use_function/ignore_constants.phpt @@ -0,0 +1,23 @@ +--TEST-- +use function should ignore namespaced constants +--FILE-- +<?php + +namespace foo { + const bar = 42; +} + +namespace { + const bar = 43; +} + +namespace { + use function foo\bar; + var_dump(bar); + echo "Done\n"; +} + +?> +--EXPECT-- +int(43) +Done diff --git a/Zend/tests/use_function/includes/foo_bar.php b/Zend/tests/use_function/includes/foo_bar.php new file mode 100644 index 0000000000..6d2f8cab45 --- /dev/null +++ b/Zend/tests/use_function/includes/foo_bar.php @@ -0,0 +1,7 @@ +<?php + +namespace foo; + +function bar() { + return 'local bar'; +} diff --git a/Zend/tests/use_function/includes/foo_strlen.php b/Zend/tests/use_function/includes/foo_strlen.php new file mode 100644 index 0000000000..d2df2aa2b4 --- /dev/null +++ b/Zend/tests/use_function/includes/foo_strlen.php @@ -0,0 +1,7 @@ +<?php + +namespace foo; + +function strlen($str) { + return 4; +} diff --git a/Zend/tests/use_function/includes/global_bar.php b/Zend/tests/use_function/includes/global_bar.php new file mode 100644 index 0000000000..6d7d91f805 --- /dev/null +++ b/Zend/tests/use_function/includes/global_bar.php @@ -0,0 +1,5 @@ +<?php + +function bar() { + return 'global bar'; +} diff --git a/Zend/tests/use_function/includes/global_baz.php b/Zend/tests/use_function/includes/global_baz.php new file mode 100644 index 0000000000..6383b9dd38 --- /dev/null +++ b/Zend/tests/use_function/includes/global_baz.php @@ -0,0 +1,4 @@ +<?php + +function baz() { +} diff --git a/Zend/tests/use_function/no_global_fallback.phpt b/Zend/tests/use_function/no_global_fallback.phpt new file mode 100644 index 0000000000..6597d0d301 --- /dev/null +++ b/Zend/tests/use_function/no_global_fallback.phpt @@ -0,0 +1,13 @@ +--TEST-- +non-existent imported functions should not be looked up in the global table +--FILE-- +<?php + +require 'includes/global_baz.php'; + +use function foo\bar\baz; +var_dump(baz()); + +?> +--EXPECTF-- +Fatal error: Call to undefined function foo\bar\baz() in %s on line %d diff --git a/Zend/tests/use_function/no_global_fallback2.phpt b/Zend/tests/use_function/no_global_fallback2.phpt new file mode 100644 index 0000000000..5d012c10e5 --- /dev/null +++ b/Zend/tests/use_function/no_global_fallback2.phpt @@ -0,0 +1,18 @@ +--TEST-- +non-existent imported functions should not be looked up in the global table +--FILE-- +<?php + +namespace { + function test() { + echo "NO!"; + } +} +namespace foo { + use function bar\test; + test(); +} + +?> +--EXPECTF-- +Fatal error: Call to undefined function bar\test() in %s on line %d diff --git a/Zend/tests/use_function/self_parent.phpt b/Zend/tests/use_function/self_parent.phpt new file mode 100644 index 0000000000..f1e1fa84f1 --- /dev/null +++ b/Zend/tests/use_function/self_parent.phpt @@ -0,0 +1,12 @@ +--TEST-- +Allow self and parent in use function statement +--FILE-- +<?php + +namespace { + use function self as foo; + use function parent as bar; +} + +?> +--EXPECT-- diff --git a/Zend/tests/use_function/shadow_core.phpt b/Zend/tests/use_function/shadow_core.phpt new file mode 100644 index 0000000000..8f92ff1e1b --- /dev/null +++ b/Zend/tests/use_function/shadow_core.phpt @@ -0,0 +1,16 @@ +--TEST-- +shadowing a global core function with a local version +--FILE-- +<?php + +require 'includes/foo_strlen.php'; + +use function foo\strlen; + +var_dump(strlen('foo bar baz')); +echo "Done\n"; + +?> +--EXPECT-- +int(4) +Done diff --git a/Zend/tests/use_function/shadow_global.phpt b/Zend/tests/use_function/shadow_global.phpt new file mode 100644 index 0000000000..791bcdf4d5 --- /dev/null +++ b/Zend/tests/use_function/shadow_global.phpt @@ -0,0 +1,25 @@ +--TEST-- +shadowing a global function with a local version +--FILE-- +<?php + +namespace { + require 'includes/global_bar.php'; + require 'includes/foo_bar.php'; +} + +namespace { + var_dump(bar()); +} + +namespace { + use function foo\bar; + var_dump(bar()); + echo "Done\n"; +} + +?> +--EXPECT-- +string(10) "global bar" +string(9) "local bar" +Done |