com php-src: Remove mentions of "type hint" and "typehint": Zend/tests/array_type_hint_001.phpt Zend/tests/ bug42802.phpt Zend/tests/bug69767.php t
Zend/tests/callable_type_hint_001.phpt Zend /tests/callable_type_hint_002.phpt Zend/tests/c allable_type_hint_003.phpt Zend/tests/closure _059.phpt
Zend/tests/closure_with_variadic_ty pehint.phpt Zend/tests/errmsg_013.phpt Zend/tes ts/generators/get_return.phpt Zend/tests/ns_055 .phpt
Zend/tests/return_types/
| From: | JulienPauli | Date: | Thu, 24 Dec 2015 14:19:31 +0000 |
| Subject: | com php-src: Remove mentions of "type hint" and "typehint": Zend/tests/array_type_hint_001.phpt Zend/tests/ bug42802.phpt Zend/tests/bug69767.php t Zend/tests/callable_type_hint_001.phpt Zend /tests/callable_type_hint_002.phpt Zend/tests/c allable_type_hint_003.phpt Zend/tests/closure _059.phpt Zend/tests/closure_with_variadic_ty pehint.phpt Zend/tests/errmsg_013.phpt Zend/tes ts/generators/get_return.phpt Zend/tests/ns_055 .phpt Zend/tests/return_types/ |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90459@lists.php.net to get a copy of this message | ||
Commit: 2a7eeff33e6b798c0b36a0a0e52fbf8c3197f4e9
Author: Levi Morrison <levim@php.net> Tue, 20 Oct 2015 10:50:13 -0600
Committer: Julien Pauli <jpauli@php.net> Thu, 24 Dec 2015 15:19:31 +0100
Parents: 8182f0ff2a95fe1f6382dc9a74c48585aec46493
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2a7eeff33e6b798c0b36a0a0e52fbf8c3197f4e9
Log:
Remove mentions of "type hint" and "typehint"
Changed paths:
D Zend/tests/array_type_hint_001.phpt
M Zend/tests/bug42802.phpt
M Zend/tests/bug69767.phpt
D Zend/tests/callable_type_hint_001.phpt
D Zend/tests/callable_type_hint_002.phpt
D Zend/tests/callable_type_hint_003.phpt
M Zend/tests/closure_059.phpt
D Zend/tests/closure_with_variadic_typehint.phpt
M Zend/tests/errmsg_013.phpt
M Zend/tests/generators/get_return.phpt
M Zend/tests/ns_055.phpt
M Zend/tests/return_types/internal_functions001.phpt
M Zend/tests/return_types/internal_functions002.phpt
M Zend/tests/return_types/reflection001.phpt
A Zend/tests/type_declarations/add_return_type.phpt
A Zend/tests/type_declarations/array_001..phpt
A Zend/tests/type_declarations/callable_001.phpt
A Zend/tests/type_declarations/callable_002.phpt
A Zend/tests/type_declarations/callable_003.phpt
A Zend/tests/type_declarations/closure_with_variadic..phpt
A Zend/tests/type_declarations/default_boolean_hint_values.phpt
A Zend/tests/type_declarations/explicit_weak_include_strict.phpt
A Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt
A Zend/tests/type_declarations/internal_function_strict_mode.phpt
A Zend/tests/type_declarations/return_separation.phpt
A Zend/tests/type_declarations/scalar_basic.phpt
A Zend/tests/type_declarations/scalar_constant_defaults.phpt
A Zend/tests/type_declarations/scalar_constant_defaults_error.phpt
A Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt
A Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt
A Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt
A Zend/tests/type_declarations/scalar_none.phpt
A Zend/tests/type_declarations/scalar_null.phpt
A Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt
A Zend/tests/type_declarations/scalar_reserved2.phpt
A Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt
A Zend/tests/type_declarations/scalar_reserved2_use.phpt
A Zend/tests/type_declarations/scalar_reserved3.phpt
A Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt
A Zend/tests/type_declarations/scalar_reserved3_use.phpt
A Zend/tests/type_declarations/scalar_reserved4.phpt
A Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt
A Zend/tests/type_declarations/scalar_reserved4_use.phpt
A Zend/tests/type_declarations/scalar_reserved6.phpt
A Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt
A Zend/tests/type_declarations/scalar_reserved6_use.phpt
A Zend/tests/type_declarations/scalar_reserved7.phpt
A Zend/tests/type_declarations/scalar_return_basic.phpt
A Zend/tests/type_declarations/scalar_return_basic_64bit.phpt
A Zend/tests/type_declarations/scalar_strict.phpt
A Zend/tests/type_declarations/scalar_strict_64bit.phpt
A Zend/tests/type_declarations/scalar_strict_basic.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt
A Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt
A Zend/tests/type_declarations/scalar_weak_reference.phpt
A Zend/tests/type_declarations/self_on_closure_in_method.phpt
A Zend/tests/type_declarations/strict_call_weak.phpt
A Zend/tests/type_declarations/strict_call_weak_2.inc
A Zend/tests/type_declarations/strict_call_weak_explicit.phpt
A Zend/tests/type_declarations/strict_call_weak_explicit_2.inc
A Zend/tests/type_declarations/strict_include_explicit_weak.phpt
A Zend/tests/type_declarations/strict_include_explicit_weak_2.inc
A Zend/tests/type_declarations/strict_include_weak.phpt
A Zend/tests/type_declarations/strict_include_weak_2.inc
A Zend/tests/type_declarations/strict_nested.phpt
A Zend/tests/type_declarations/weak_call_strict.phpt
A Zend/tests/type_declarations/weak_call_strict_2.inc
A Zend/tests/type_declarations/weak_explicit_call_strict.phpt
A Zend/tests/type_declarations/weak_include_strict.phpt
A Zend/tests/type_declarations/weak_include_strict_2.inc
D Zend/tests/typehints/add_return_type.phpt
D Zend/tests/typehints/default_boolean_hint_values.phpt
D Zend/tests/typehints/explicit_weak_include_strict.phpt
D Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt
D Zend/tests/typehints/internal_function_strict_mode.phpt
D Zend/tests/typehints/return_separation.phpt
D Zend/tests/typehints/scalar_basic.phpt
D Zend/tests/typehints/scalar_constant_defaults.phpt
D Zend/tests/typehints/scalar_constant_defaults_error.phpt
D Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt
D Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt
D Zend/tests/typehints/scalar_float_with_invalid_default.phpt
D Zend/tests/typehints/scalar_none.phpt
D Zend/tests/typehints/scalar_null.phpt
D Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt
D Zend/tests/typehints/scalar_reserved2.phpt
D Zend/tests/typehints/scalar_reserved2_class_alias.phpt
D Zend/tests/typehints/scalar_reserved2_use.phpt
D Zend/tests/typehints/scalar_reserved3.phpt
D Zend/tests/typehints/scalar_reserved3_class_alias.phpt
D Zend/tests/typehints/scalar_reserved3_use.phpt
D Zend/tests/typehints/scalar_reserved4.phpt
D Zend/tests/typehints/scalar_reserved4_class_alias.phpt
D Zend/tests/typehints/scalar_reserved4_use.phpt
D Zend/tests/typehints/scalar_reserved6.phpt
D Zend/tests/typehints/scalar_reserved6_class_alias.phpt
D Zend/tests/typehints/scalar_reserved6_use.phpt
D Zend/tests/typehints/scalar_reserved7.phpt
D Zend/tests/typehints/scalar_return_basic.phpt
D Zend/tests/typehints/scalar_return_basic_64bit.phpt
D Zend/tests/typehints/scalar_strict.phpt
D Zend/tests/typehints/scalar_strict_64bit.phpt
D Zend/tests/typehints/scalar_strict_basic.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt
D Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt
D Zend/tests/typehints/scalar_weak_reference.phpt
D Zend/tests/typehints/self_on_closure_in_method.phpt
D Zend/tests/typehints/strict_call_weak.phpt
D Zend/tests/typehints/strict_call_weak_2.inc
D Zend/tests/typehints/strict_call_weak_explicit.phpt
D Zend/tests/typehints/strict_call_weak_explicit_2.inc
D Zend/tests/typehints/strict_include_explicit_weak.phpt
D Zend/tests/typehints/strict_include_explicit_weak_2.inc
D Zend/tests/typehints/strict_include_weak.phpt
D Zend/tests/typehints/strict_include_weak_2.inc
D Zend/tests/typehints/strict_nested.phpt
D Zend/tests/typehints/weak_call_strict.phpt
D Zend/tests/typehints/weak_call_strict_2.inc
D Zend/tests/typehints/weak_explicit_call_strict.phpt
D Zend/tests/typehints/weak_include_strict.phpt
D Zend/tests/typehints/weak_include_strict_2.inc
M Zend/tests/variadic/typehint_error.phpt
M Zend/tests/variadic/typehint_suppressed_error.phpt
M Zend/zend_compile.c
M Zend/zend_compile.h
M Zend/zend_inheritance.c
M tests/lang/type_hints_003.phpt
diff --git a/Zend/tests/array_type_hint_001.phpt b/Zend/tests/array_type_hint_001.phpt deleted file mode 100644 index 2b473c5..0000000 --- a/Zend/tests/array_type_hint_001.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Array type hint ---FILE-- -<?php -function foo(array $a) { - echo count($a)."\n"; -} - -foo(array(1,2,3)); -foo(123); -?> ---EXPECTF-- -3 - -Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type array, integer given, called in %sarray_type_hint_001.php on line 7 and defined in %sarray_type_hint_001.php:2 -Stack trace: -#0 %s(%d): foo(123) -#1 {main} - thrown in %sarray_type_hint_001.php on line 2 diff --git a/Zend/tests/bug42802.phpt b/Zend/tests/bug42802.phpt index 3b00408..ebfb528 100644 --- a/Zend/tests/bug42802.phpt +++ b/Zend/tests/bug42802.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #42802 (Namespace not supported in typehints) +Bug #42802 (Namespace not supported in types) --FILE-- <?php namespace foo; diff --git a/Zend/tests/bug69767.phpt b/Zend/tests/bug69767.phpt index cf4d4e7..9458546 100644 --- a/Zend/tests/bug69767.phpt +++ b/Zend/tests/bug69767.phpt @@ -5,4 +5,4 @@ Bug #69767 (Default parameter value with wrong type segfaults) function foo(String $bar = 0) {} ?> --EXPECTF-- -Fatal error: Default value for parameters with a string type hint can only be string or NULL in %sbug69767.php on line %d +Fatal error: Default value for parameters with a string type can only be string or NULL in %sbug69767.php on line %d diff --git a/Zend/tests/callable_type_hint_001.phpt b/Zend/tests/callable_type_hint_001.phpt deleted file mode 100644 index 5ab892c..0000000 --- a/Zend/tests/callable_type_hint_001.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -callable type hint#001 ---FILE-- -<?php - -class bar { - function baz() {} - static function foo() {} -} -function foo(callable $bar) { - var_dump($bar); -} -$closure = function () {}; - -foo("strpos"); -foo("foo"); -foo(array("bar", "baz")); -foo(array("bar", "foo")); -foo($closure); ---EXPECTF-- -string(6) "strpos" -string(3) "foo" - -Deprecated: Non-static method bar::baz() should not be called statically in %scallable_type_hint_001.php on line %d -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(3) "baz" -} -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(3) "foo" -} -object(Closure)#%d (0) { -} - diff --git a/Zend/tests/callable_type_hint_002.phpt b/Zend/tests/callable_type_hint_002.phpt deleted file mode 100644 index b1b7339..0000000 --- a/Zend/tests/callable_type_hint_002.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -callable type hint#002 - Reflection ---FILE-- -<?php - -class bar { - static function foo(callable $arg) {} -} -function foo(callable $bar) { -} -$closure = function (callable $arg) {}; - -$rf = new ReflectionFunction("foo"); -var_dump($rf->getParameters()[0]->isCallable()); - -$rm = new ReflectionMethod("bar", "foo"); -var_dump($rm->getParameters()[0]->isCallable()); - -$rc = new ReflectionFunction($closure); -var_dump($rc->getParameters()[0]->isCallable()); - -?> ---EXPECT-- -bool(true) -bool(true) -bool(true) - diff --git a/Zend/tests/callable_type_hint_003.phpt b/Zend/tests/callable_type_hint_003.phpt deleted file mode 100644 index 83f5090..0000000 --- a/Zend/tests/callable_type_hint_003.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -callable type hint#003 ---FILE-- -<?php - -function foo(callable $a, $b, callable $c) { - var_dump($a, $b, $c); -} -function bar(callable $a = null) { - var_dump($a); -} - -foo("strpos", 123, "strpos"); -bar("substr"); -?> ---EXPECT-- -string(6) "strpos" -int(123) -string(6) "strpos" -string(6) "substr" - diff --git a/Zend/tests/closure_059.phpt b/Zend/tests/closure_059.phpt index 1ee7fe6..299d8f5 100644 --- a/Zend/tests/closure_059.phpt +++ b/Zend/tests/closure_059.phpt @@ -1,5 +1,5 @@ --TEST-- -Closure 059: Closure type hinting +Closure 059: Closure type declaration --FILE-- <?php class A { diff --git a/Zend/tests/closure_with_variadic_typehint.phpt b/Zend/tests/closure_with_variadic_typehint.phpt deleted file mode 100644 index 3e91a6f..0000000 --- a/Zend/tests/closure_with_variadic_typehint.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Closure with variadic type hint ---FILE-- -<?php -$f = function (stdClass ...$a) { - var_dump($a); -}; -$f(new stdClass); -?> ---EXPECT-- -array(1) { - [0]=> - object(stdClass)#2 (0) { - } -} diff --git a/Zend/tests/errmsg_013.phpt b/Zend/tests/errmsg_013.phpt index d1f248e..327d75e 100644 --- a/Zend/tests/errmsg_013.phpt +++ b/Zend/tests/errmsg_013.phpt @@ -1,5 +1,5 @@ --TEST-- -errmsg: default value for parameters with array type hint can only be an array or NULL +errmsg: default value for parameters with array type can only be an array or NULL --FILE-- <?php @@ -11,4 +11,4 @@ class test { echo "Done\n"; ?> --EXPECTF-- -Fatal error: Default value for parameters with array type hint can only be an array or NULL in %s on line %d +Fatal error: Default value for parameters with array type can only be an array or NULL in %s on line %d diff --git a/Zend/tests/generators/get_return.phpt b/Zend/tests/generators/get_return.phpt index c996eb4..0d3e32a 100644 --- a/Zend/tests/generators/get_return.phpt +++ b/Zend/tests/generators/get_return.phpt @@ -58,7 +58,7 @@ $gen->next(); var_dump($gen->getReturn()); // Explicit value-less return also results in a NULL generator -// return value and there is no interference with type hints +// return value and there is no interference with type declarations function gen6() : Generator { return; yield 24; diff --git a/Zend/tests/ns_055.phpt b/Zend/tests/ns_055.phpt index a692e47..16e3e69 100644 --- a/Zend/tests/ns_055.phpt +++ b/Zend/tests/ns_055.phpt @@ -1,5 +1,5 @@ --TEST-- -055: typehints in namespaces +055: types in namespaces --FILE-- <?php namespace test\ns1; diff --git a/Zend/tests/return_types/internal_functions001.phpt b/Zend/tests/return_types/internal_functions001.phpt index 66c7123..fffaf54 100644 --- a/Zend/tests/return_types/internal_functions001.phpt +++ b/Zend/tests/return_types/internal_functions001.phpt @@ -1,5 +1,5 @@ --TEST-- -Return type hinting for internal functions +Return type for internal functions --SKIPIF-- <?php diff --git a/Zend/tests/return_types/internal_functions002.phpt b/Zend/tests/return_types/internal_functions002.phpt index 65838a1..7cdb2b8 100644 --- a/Zend/tests/return_types/internal_functions002.phpt +++ b/Zend/tests/return_types/internal_functions002.phpt @@ -1,5 +1,5 @@ --TEST-- -Return type hinting for internal functions 2 +Return type for internal functions 2 --SKIPIF-- <?php diff --git a/Zend/tests/return_types/reflection001.phpt b/Zend/tests/return_types/reflection001.phpt index f616504..6492ee1 100644 --- a/Zend/tests/return_types/reflection001.phpt +++ b/Zend/tests/return_types/reflection001.phpt @@ -1,5 +1,5 @@ --TEST-- -Return type hinting and Reflection::export() +Return type and Reflection::export() --SKIPIF-- <?php diff --git a/Zend/tests/type_declarations/add_return_type.phpt b/Zend/tests/type_declarations/add_return_type.phpt new file mode 100644 index 0000000..de8a17d --- /dev/null +++ b/Zend/tests/type_declarations/add_return_type.phpt @@ -0,0 +1,23 @@ +--TEST-- +Adding a return type during inheritance is allowed +--FILE-- +<?php + +interface One { + public function a(); + public function b(); + public function c(); + public function d(); +} + +interface Two extends One { + public function a() : stdClass; + public function c() : callable; + public function b() : array; + public function d() : int; +} + +?> +Done +--EXPECT-- +Done diff --git a/Zend/tests/type_declarations/array_001.phpt b/Zend/tests/type_declarations/array_001.phpt new file mode 100644 index 0000000..8fc368e --- /dev/null +++ b/Zend/tests/type_declarations/array_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +Array type declaration +--FILE-- +<?php +function foo(array $a) { + echo count($a)."\n"; +} + +foo(array(1,2,3)); +foo(123); +?> +--EXPECTF-- +3 + +Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type array, integer given, called in %s on line 7 and defined in %s:2 +Stack trace: +#0 %s(%d): foo(123) +#1 {main} + thrown in %s on line 2 diff --git a/Zend/tests/type_declarations/callable_001.phpt b/Zend/tests/type_declarations/callable_001.phpt new file mode 100644 index 0000000..0466288 --- /dev/null +++ b/Zend/tests/type_declarations/callable_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +callable type#001 +--FILE-- +<?php + +class bar { + function baz() {} + static function foo() {} +} +function foo(callable $bar) { + var_dump($bar); +} +$closure = function () {}; + +foo("strpos"); +foo("foo"); +foo(array("bar", "baz")); +foo(array("bar", "foo")); +foo($closure); +--EXPECTF-- +string(6) "strpos" +string(3) "foo" + +Deprecated: Non-static method bar::baz() should not be called statically in %s on line %d +array(2) { + [0]=> + string(3) "bar" + [1]=> + string(3) "baz" +} +array(2) { + [0]=> + string(3) "bar" + [1]=> + string(3) "foo" +} +object(Closure)#%d (0) { +} + diff --git a/Zend/tests/type_declarations/callable_002.phpt b/Zend/tests/type_declarations/callable_002.phpt new file mode 100644 index 0000000..01b6945 --- /dev/null +++ b/Zend/tests/type_declarations/callable_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +callable type#002 - Reflection +--FILE-- +<?php + +class bar { + static function foo(callable $arg) {} +} +function foo(callable $bar) { +} +$closure = function (callable $arg) {}; + +$rf = new ReflectionFunction("foo"); +var_dump($rf->getParameters()[0]->isCallable()); + +$rm = new ReflectionMethod("bar", "foo"); +var_dump($rm->getParameters()[0]->isCallable()); + +$rc = new ReflectionFunction($closure); +var_dump($rc->getParameters()[0]->isCallable()); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) + diff --git a/Zend/tests/type_declarations/callable_003.phpt b/Zend/tests/type_declarations/callable_003.phpt new file mode 100644 index 0000000..b5e722c --- /dev/null +++ b/Zend/tests/type_declarations/callable_003.phpt @@ -0,0 +1,21 @@ +--TEST-- +callable type#003 +--FILE-- +<?php + +function foo(callable $a, $b, callable $c) { + var_dump($a, $b, $c); +} +function bar(callable $a = null) { + var_dump($a); +} + +foo("strpos", 123, "strpos"); +bar("substr"); +?> +--EXPECT-- +string(6) "strpos" +int(123) +string(6) "strpos" +string(6) "substr" + diff --git a/Zend/tests/type_declarations/closure_with_variadic.phpt b/Zend/tests/type_declarations/closure_with_variadic.phpt new file mode 100644 index 0000000..acbf57f --- /dev/null +++ b/Zend/tests/type_declarations/closure_with_variadic.phpt @@ -0,0 +1,15 @@ +--TEST-- +Closure with variadic type declaration +--FILE-- +<?php +$f = function (stdClass ...$a) { + var_dump($a); +}; +$f(new stdClass); +?> +--EXPECT-- +array(1) { + [0]=> + object(stdClass)#2 (0) { + } +} diff --git a/Zend/tests/type_declarations/default_boolean_hint_values.phpt b/Zend/tests/type_declarations/default_boolean_hint_values.phpt new file mode 100644 index 0000000..6ba2628 --- /dev/null +++ b/Zend/tests/type_declarations/default_boolean_hint_values.phpt @@ -0,0 +1,16 @@ +--TEST-- +Default values for boolean hints should work +--FILE-- +<?php + +function foo(bool $x = true, bool $y = false) { + var_dump($x, $y); +} + + + +foo(); +?> +--EXPECTF-- +bool(true) +bool(false) diff --git a/Zend/tests/type_declarations/explicit_weak_include_strict.phpt b/Zend/tests/type_declarations/explicit_weak_include_strict.phpt new file mode 100644 index 0000000..fb53d8c --- /dev/null +++ b/Zend/tests/type_declarations/explicit_weak_include_strict.phpt @@ -0,0 +1,19 @@ +--TEST-- +explicitly strict_types=0 code including strict_types=1 code +--FILE-- +<?php + +declare(strict_types=0); + +// file with strict_types=1 +require 'weak_include_strict_2.inc'; + +// calls within that file should stay strict, despite being included by weak file +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 +Stack trace: +#0 %s(%d): takes_int(1) +#1 %s(%d): require('%s') +#2 {main} + thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt b/Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt new file mode 100644 index 0000000..2f6c881 --- /dev/null +++ b/Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt @@ -0,0 +1,16 @@ +--TEST-- +Inexistent class as type receiving scalar argument +--FILE-- +<?php + +function foo(bar $ex) {} +foo(null); + +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be an instance of bar, null given, called in %s on line %d and defined in %s:%d +Stack trace: +#0 %s(%d): foo(NULL) +#1 {main} + thrown in %s on line %d + diff --git a/Zend/tests/type_declarations/internal_function_strict_mode.phpt b/Zend/tests/type_declarations/internal_function_strict_mode.phpt new file mode 100644 index 0000000..4e792fa --- /dev/null +++ b/Zend/tests/type_declarations/internal_function_strict_mode.phpt @@ -0,0 +1,35 @@ +--TEST-- +Scalar type - internal function strict mode +--FILE-- +<?php +declare(strict_types=1); + +echo "*** Trying Ord With Integer" . PHP_EOL; +try { + var_dump(ord(1)); +} catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; +} + +echo "*** Trying Array Map With Invalid Callback" . PHP_EOL; +try { + array_map([null, "bar"], []); +} catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; +} + +echo "*** Trying Strlen With Float" . PHP_EOL; +try { + var_dump(strlen(1.5)); +} catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; +} + +?> +--EXPECTF-- +*** Trying Ord With Integer +*** Caught ord() expects parameter 1 to be string, integer given +*** Trying Array Map With Invalid Callback +*** Caught array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object +*** Trying Strlen With Float +*** Caught strlen() expects parameter 1 to be string, float given diff --git a/Zend/tests/type_declarations/return_separation.phpt b/Zend/tests/type_declarations/return_separation.phpt new file mode 100644 index 0000000..7e9d095 --- /dev/null +++ b/Zend/tests/type_declarations/return_separation.phpt @@ -0,0 +1,27 @@ +--TEST-- +Return values are separated for references with rc=1 +--FILE-- +<?php + +function test1() : array { + $array = []; + $ref =& $array; + unset($ref); + return $array; +} + +function test2() : string { + $int = 42; + $ref =& $int; + unset($ref); + return $int; +} + +var_dump(test1()); +var_dump(test2()); + +?> +--EXPECT-- +array(0) { +} +string(2) "42" diff --git a/Zend/tests/type_declarations/scalar_basic.phpt b/Zend/tests/type_declarations/scalar_basic.phpt new file mode 100644 index 0000000..51c3664 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_basic.phpt @@ -0,0 +1,277 @@ +--TEST-- +Scalar type basics +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (\TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} +echo PHP_EOL . "Done"; +?> +--EXPECTF-- + +Testing 'int' type: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +int(1) + +*** Trying float(1) +int(1) + +*** Trying float(1.5) +int(1) + +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(%d) +int(%d) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +int(1) + +*** Trying bool(false) +int(0) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +float(1) + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(%d) +float(%s) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +float(1) + +*** Trying bool(false) +float(0) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying int(1) +string(1) "1" + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +string(1) "1" + +*** Trying float(1.5) +string(3) "1.5" + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(%d) +string(%d) "%d" + +*** Trying float(NAN) +string(3) "NAN" + +*** Trying bool(true) +string(1) "1" + +*** Trying bool(false) +string(0) "" + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +string(6) "foobar" + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying int(1) +bool(true) + +*** Trying string(1) "1" +bool(true) + +*** Trying float(1) +bool(true) + +*** Trying float(1.5) +bool(true) + +*** Trying string(2) "1a" +bool(true) + +*** Trying string(1) "a" +bool(true) + +*** Trying string(0) "" +bool(false) + +*** Trying int(%d) +bool(true) + +*** Trying float(NAN) +bool(true) + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_constant_defaults.phpt b/Zend/tests/type_declarations/scalar_constant_defaults.phpt new file mode 100644 index 0000000..2982d9b --- /dev/null +++ b/Zend/tests/type_declarations/scalar_constant_defaults.phpt @@ -0,0 +1,83 @@ +--TEST-- +Scalar type - default via constants +--FILE-- +<?php + +const INT_VAL = 10; +const FLOAT_VAL = 10.5; +const STRING_VAL = "this is a test"; +const INT_ADD_VAL = 10 + 15; +const FLOAT_ADD_VAL = 10.5 + 0.2; +const STRING_ADD_VAL = "this" . " is a test"; +const NULL_VAL = null; + +function int_val(int $a = INT_VAL): int { + return $a; +} + +function float_val(float $a = FLOAT_VAL): float { + return $a; +} + +function string_val(string $a = STRING_VAL): string { + return $a; +} + +function int_add_val(int $a = INT_ADD_VAL): int { + return $a; +} + +function float_add_val(float $a = FLOAT_ADD_VAL): float { + return $a; +} + +function string_add_val(string $a = STRING_ADD_VAL): string { + return $a; +} + +function int_val_default_null(int $a = NULL_VAL) { + return $a; +} + +echo "Testing int val" . PHP_EOL; +var_dump(int_val()); + +echo "Testing float val" . PHP_EOL; +var_dump(float_val()); + +echo "Testing string val" . PHP_EOL; +var_dump(string_val()); + +echo "Testing int add val" . PHP_EOL; +var_dump(int_add_val()); + +echo "Testing float add val" . PHP_EOL; +var_dump(float_add_val()); + +echo "Testing string add val" . PHP_EOL; +var_dump(string_add_val()); + +echo "Testing int with default null constant" . PHP_EOL; +var_dump(int_val_default_null()); + +echo "Testing int with null null constant" . PHP_EOL; +var_dump(int_val_default_null(null)); + +?> +--EXPECTF-- +Testing int val +int(10) +Testing float val +float(10.5) +Testing string val +string(14) "this is a test" +Testing int add val +int(25) +Testing float add val +float(10.7) +Testing string add val +string(14) "this is a test" +Testing int with default null constant +NULL +Testing int with null null constant +NULL diff --git a/Zend/tests/type_declarations/scalar_constant_defaults_error.phpt b/Zend/tests/type_declarations/scalar_constant_defaults_error.phpt new file mode 100644 index 0000000..dcbb3e8 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_constant_defaults_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +Scalar type - default via constants - error condition +--FILE-- +<?php + +const STRING_VAL = "test"; + +function int_val(int $a = STRING_VAL): int { + return $a; +} + +var_dump(int_val()); + +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to int_val() must be of the type integer, string given, called in %s on line %d and defined in %s:%d +Stack trace: +#0 %s(%d): int_val() +#1 {main} + thrown in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt b/Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt new file mode 100644 index 0000000..5e85eba --- /dev/null +++ b/Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt @@ -0,0 +1,17 @@ +--TEST-- +Float type should allow an integer as default even with strict types +--FILE-- +<?php + +declare(strict_types=1); + +function test(float $arg = 0) +{ + var_dump($arg); +} + +test(); + +?> +--EXPECT-- +float(0) diff --git a/Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt b/Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt new file mode 100644 index 0000000..0289e13 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt @@ -0,0 +1,15 @@ +--TEST-- +Float type should allow an integer as default +--FILE-- +<?php + +function test(float $arg = 0) +{ + var_dump($arg); +} + +test(); + +?> +--EXPECT-- +float(0) diff --git a/Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt b/Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt new file mode 100644 index 0000000..7bc2fda --- /dev/null +++ b/Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt @@ -0,0 +1,16 @@ +--TEST-- +Float type should not allow invalid types as default +--FILE-- +<?php + +function test(float $arg = true) +{ + var_dump($arg); +} + +test(); + +?> +--EXPECTF-- + +Fatal error: Default value for parameters with a float type can only be float, integer, or NULL in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_none.phpt b/Zend/tests/type_declarations/scalar_none.phpt new file mode 100644 index 0000000..3bec609 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_none.phpt @@ -0,0 +1,54 @@ +--TEST-- +Scalar type missing parameters +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; }, + 'int nullable' => function (int $i = NULL) { return $i; }, + 'float nullable' => function (float $f = NULL) { return $f; }, + 'string nullable' => function (string $s = NULL) { return $s; }, + 'bool nullable' => function (bool $b = NULL) { return $b; } +]; + +foreach ($functions as $type => $function) { + echo "Testing $type:", PHP_EOL; + try { + var_dump($function()); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } +} +echo PHP_EOL . "Done"; +--EXPECTF-- +Testing int: +*** Caught Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d +Testing float: +*** Caught Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d +Testing string: +*** Caught Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d +Testing bool: +*** Caught Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d +Testing int nullable: +NULL +Testing float nullable: +NULL +Testing string nullable: +NULL +Testing bool nullable: +NULL + +Done diff --git a/Zend/tests/type_declarations/scalar_null.phpt b/Zend/tests/type_declarations/scalar_null.phpt new file mode 100644 index 0000000..6b9930f --- /dev/null +++ b/Zend/tests/type_declarations/scalar_null.phpt @@ -0,0 +1,56 @@ +--TEST-- +Scalar type nullability +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; }, + 'int nullable' => function (int $i = NULL) { return $i; }, + 'float nullable' => function (float $f = NULL) { return $f; }, + 'string nullable' => function (string $s = NULL) { return $s; }, + 'bool nullable' => function (bool $b = NULL) { return $b; } +]; + +foreach ($functions as $type => $function) { + echo "Testing $type:", PHP_EOL; + try { + var_dump($function(null)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing int: +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d +Testing float: +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d +Testing string: +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d +Testing bool: +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d +Testing int nullable: +NULL +Testing float nullable: +NULL +Testing string nullable: +NULL +Testing bool nullable: +NULL + +Done diff --git a/Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt b/Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt new file mode 100644 index 0000000..b093983 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt @@ -0,0 +1,14 @@ +--TEST-- +Scalar type - disallow relative types +--FILE-- +<?php + +function foo(bar\int $a): int { + return $a; +} + +foo(10); + +?> +--EXPECTF-- +Fatal error: Cannot use 'bar\int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved2.phpt b/Zend/tests/type_declarations/scalar_reserved2.phpt new file mode 100644 index 0000000..893f4b5 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved2.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (2) +--FILE-- +<?php + +class int {} +--EXPECTF-- +Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt new file mode 100644 index 0000000..777cf9c --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (2) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "int"); +--EXPECTF-- +Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved2_use.phpt b/Zend/tests/type_declarations/scalar_reserved2_use.phpt new file mode 100644 index 0000000..3e8d1be --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved2_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (2) - use +--FILE-- +<?php + +use foobar as int; +--EXPECTF-- +Fatal error: Cannot use foobar as int because 'int' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved3.phpt b/Zend/tests/type_declarations/scalar_reserved3.phpt new file mode 100644 index 0000000..433673e --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved3.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (3) +--FILE-- +<?php + +class float {} +--EXPECTF-- +Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt new file mode 100644 index 0000000..dc8f319 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (3) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "float"); +--EXPECTF-- +Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved3_use.phpt b/Zend/tests/type_declarations/scalar_reserved3_use.phpt new file mode 100644 index 0000000..af76abf --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved3_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (3) - use +--FILE-- +<?php + +use foobar as float; +--EXPECTF-- +Fatal error: Cannot use foobar as float because 'float' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved4.phpt b/Zend/tests/type_declarations/scalar_reserved4.phpt new file mode 100644 index 0000000..dd5ff89 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved4.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (4) +--FILE-- +<?php + +class string {} +--EXPECTF-- +Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt new file mode 100644 index 0000000..ebb6ac3 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (4) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "string"); +--EXPECTF-- +Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved4_use.phpt b/Zend/tests/type_declarations/scalar_reserved4_use.phpt new file mode 100644 index 0000000..e2fc0ae --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved4_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (4) - use +--FILE-- +<?php + +use foobar as string; +--EXPECTF-- +Fatal error: Cannot use foobar as string because 'string' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved6.phpt b/Zend/tests/type_declarations/scalar_reserved6.phpt new file mode 100644 index 0000000..f84ec94 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved6.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (6) +--FILE-- +<?php + +class bool {} +--EXPECTF-- +Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt new file mode 100644 index 0000000..8a777ec --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (6) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "bool"); +--EXPECTF-- +Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved6_use.phpt b/Zend/tests/type_declarations/scalar_reserved6_use.phpt new file mode 100644 index 0000000..e9de61f --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved6_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (6) - use +--FILE-- +<?php + +use foobar as bool; +--EXPECTF-- +Fatal error: Cannot use foobar as bool because 'bool' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved7.phpt b/Zend/tests/type_declarations/scalar_reserved7.phpt new file mode 100644 index 0000000..1e23d59 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved7.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (7) +--FILE-- +<?php +namespace foo; + +class int {} +--EXPECTF-- +Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_return_basic.phpt b/Zend/tests/type_declarations/scalar_return_basic.phpt new file mode 100644 index 0000000..4e0650e --- /dev/null +++ b/Zend/tests/type_declarations/scalar_return_basic.phpt @@ -0,0 +1,216 @@ +--TEST-- +Return scalar type basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying int(2147483647) +int(2147483647) +*** Trying float(NAN) +*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d + +Testing 'float' type: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying int(2147483647) +float(2147483647) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d + +Testing 'string' type: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(2147483647) +string(10) "2147483647" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +string(6) "foobar" +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d + +Testing 'bool' type: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(2147483647) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt new file mode 100644 index 0000000..e8f69bc --- /dev/null +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -0,0 +1,216 @@ +--TEST-- +Return scalar type basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying int(9223372036854775807) +int(9223372036854775807) +*** Trying float(NAN) +*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d + +Testing 'float' type: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d + +Testing 'string' type: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(9223372036854775807) +string(19) "9223372036854775807" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +string(6) "foobar" +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d + +Testing 'bool' type: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(9223372036854775807) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict.phpt b/Zend/tests/type_declarations/scalar_strict.phpt new file mode 100644 index 0000000..40b036e --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict.phpt @@ -0,0 +1,279 @@ +--TEST-- +Scalar type strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> +--FILE-- +<?php +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(2147483647) +int(2147483647) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(2147483647) +float(2147483647) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(2147483647) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying int(2147483647) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict_64bit.phpt b/Zend/tests/type_declarations/scalar_strict_64bit.phpt new file mode 100644 index 0000000..3e748ed --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_64bit.phpt @@ -0,0 +1,279 @@ +--TEST-- +Scalar type strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +int(9223372036854775807) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict_basic.phpt b/Zend/tests/type_declarations/scalar_strict_basic.phpt new file mode 100644 index 0000000..3ee94a2 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_basic.phpt @@ -0,0 +1,181 @@ +--TEST-- +Strict scalar type basics +--FILE-- +<?php + +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; + +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +$values = [ + 1, + 1.0, + "1", + TRUE, + FALSE, + NULL, + [], + new StdClass, + fopen("data:text/plain,foobar", "r") +]; + +function type($value) { + if (is_float($value)) { + return "float"; + } else if (is_bool($value)) { + return $value ? "true" : "false"; + } else if (is_null($value)) { + return "null"; + } else { + return gettype($value); + } +} + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + $errored = false; + echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL; + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: + +*** Trying integer value +int(1) + +*** Trying float value +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string value +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying true value +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying false value +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying integer value +float(1) + +*** Trying float value +float(1) + +*** Trying string value +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying true value +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying false value +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying integer value +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float value +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string value +string(1) "1" + +*** Trying true value +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying false value +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying integer value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying true value +bool(true) + +*** Trying false value +bool(false) + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt new file mode 100644 index 0000000..2a2b3e6 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test strict declaration being first operation only +--FILE-- +<?php + +function takes_int(int $x) { + global $errored; + if ($errored) { + echo "Failure!", PHP_EOL; + $errored = FALSE; + } else { + echo "Success!", PHP_EOL; + } +} + +?> +<?php + +declare(strict_types=1); +var_dump(takes_int(32)); + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt new file mode 100644 index 0000000..09ac111 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test strict declaration being first operation only 002 +--FILE-- +<?php + +namespace Foo; + +declare(strict_types=1); + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt new file mode 100644 index 0000000..6ec5b59 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt @@ -0,0 +1,11 @@ +--TEST-- +Test strict declaration being first operation only 003 +--FILE-- +hi<?php + +declare(strict_types=1); +var_dump(strlen(32)); + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt new file mode 100644 index 0000000..6000324 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test strict declaration being first operation only 004 +--FILE-- +<?php +declare(strict_types=1); + +namespace Foo { + function add1(int $arg): int { + return $arg + 1; + } +} + +namespace { + var_dump(Foo\add1(123)); +} +--EXPECT-- +int(124) diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt new file mode 100644 index 0000000..8611a20 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test strict declaration being first operation only 005 +--FILE-- +<?php + +declare(strict_types=1); + +namespace Foo; + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +int(3) \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt new file mode 100644 index 0000000..2af05b6 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test strict declaration being first operation only 006 +--SKIPIF-- +<?php +if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { + die("skip Requires configure --enable-zend-multibyte option"); +} +if (!extension_loaded("mbstring")) { + die("skip Requires mbstring extension"); +} +?> +--INI-- +zend.multibyte=1 +--FILE-- +<?php +declare(encoding="UTF-8"); +declare(strict_types=1); + +namespace Foo; + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +int(3) \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt new file mode 100644 index 0000000..3e4c693 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test strict declaration being first operation only 007 +--SKIPIF-- +<?php +if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { + die("skip Requires configure --enable-zend-multibyte option"); +} +if (!extension_loaded("mbstring")) { + die("skip Requires mbstring extension"); +} +?> +--INI-- +zend.multibyte=1 +--FILE-- +<?php +declare(strict_types=1); +declare(encoding="ISO-8859-1"); + +namespace Foo; + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +int(3) \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt new file mode 100644 index 0000000..87a09af --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt @@ -0,0 +1,11 @@ +--TEST-- +Test strict declaration block declaration 008 +--FILE-- +<?php +declare(strict_types=1) { + var_dump(strlen("abc")); +} + +?> +--EXPECTF-- +Fatal error: strict_types declaration must not use block mode in %s on line %d \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_weak_reference.phpt b/Zend/tests/type_declarations/scalar_weak_reference.phpt new file mode 100644 index 0000000..7406968 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_weak_reference.phpt @@ -0,0 +1,29 @@ +--TEST-- +Weak scalar types, with references +--FILE-- +<?php + +// implicitly weak mode code + +function to_int(int &$x) {} +function to_float(float &$x) {} +function to_string(string &$x) {} +function to_bool(bool &$x) {} + +$x = 1.0; +var_dump($x); +to_int($x); // because $x is by-reference, the weak type converts it +var_dump($x); +to_float($x); +var_dump($x); +to_string($x); +var_dump($x); +to_bool($x); +var_dump($x); +?> +--EXPECT-- +float(1) +int(1) +float(1) +string(1) "1" +bool(true) diff --git a/Zend/tests/type_declarations/self_on_closure_in_method.phpt b/Zend/tests/type_declarations/self_on_closure_in_method.phpt new file mode 100644 index 0000000..2d5bd82 --- /dev/null +++ b/Zend/tests/type_declarations/self_on_closure_in_method.phpt @@ -0,0 +1,19 @@ +--TEST-- +self return type on closure in a method +--FILE-- +<?php + +class A { + public function test() { + return function() : self { + return $this; + }; + } +} + +var_dump((new A)->test()()); + +?> +--EXPECT-- +object(A)#1 (0) { +} diff --git a/Zend/tests/type_declarations/strict_call_weak.phpt b/Zend/tests/type_declarations/strict_call_weak.phpt new file mode 100644 index 0000000..e3a606e --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak.phpt @@ -0,0 +1,21 @@ +--TEST-- +strict_types=1 code calling strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's implicitly weak +require 'strict_call_weak_2.inc'; + +// Will succeed: Function was declared in weak mode, but that does not matter +// This file uses strict mode, so the call is strict, and float denied for int +function_declared_in_weak_mode(1.0); +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak.php on line 10 and defined in %sstrict_call_weak_2.inc:5 +Stack trace: +#0 %s(%d): function_declared_in_weak_mode(1) +#1 {main} + thrown in %sstrict_call_weak_2.inc on line 5 + diff --git a/Zend/tests/type_declarations/strict_call_weak_2.inc b/Zend/tests/type_declarations/strict_call_weak_2.inc new file mode 100644 index 0000000..cba5512 --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak_2.inc @@ -0,0 +1,7 @@ +<?php + +// implicitly weak code + +function function_declared_in_weak_mode(int $x) { + echo "Success!"; +} diff --git a/Zend/tests/type_declarations/strict_call_weak_explicit.phpt b/Zend/tests/type_declarations/strict_call_weak_explicit.phpt new file mode 100644 index 0000000..22c5b43 --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak_explicit.phpt @@ -0,0 +1,21 @@ +--TEST-- +strict_types=1 code calling explicitly strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's explicitly weak +require 'strict_call_weak_explicit_2.inc'; + +// Will succeed: Function was declared in weak mode, but that does not matter +// This file uses strict mode, so the call is strict, and float denied for int +function_declared_in_weak_mode(1.0); +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak_explicit.php on line 10 and defined in %sstrict_call_weak_explicit_2.inc:5 +Stack trace: +#0 %s(%d): function_declared_in_weak_mode(1) +#1 {main} + thrown in %sstrict_call_weak_explicit_2.inc on line 5 + diff --git a/Zend/tests/type_declarations/strict_call_weak_explicit_2.inc b/Zend/tests/type_declarations/strict_call_weak_explicit_2.inc new file mode 100644 index 0000000..d26c847 --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak_explicit_2.inc @@ -0,0 +1,7 @@ +<?php + +declare(strict_types=0); + +function function_declared_in_weak_mode(int $x) { + echo "Success!"; +} diff --git a/Zend/tests/type_declarations/strict_include_explicit_weak.phpt b/Zend/tests/type_declarations/strict_include_explicit_weak.phpt new file mode 100644 index 0000000..a42d633 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_explicit_weak.phpt @@ -0,0 +1,14 @@ +--TEST-- +strict_types=1 code including explicitly strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's explicitly weak +require 'strict_include_explicit_weak_2.inc'; + +// calls within that file should stay weak, despite being included by strict fille +?> +--EXPECTF-- +Success! diff --git a/Zend/tests/type_declarations/strict_include_explicit_weak_2.inc b/Zend/tests/type_declarations/strict_include_explicit_weak_2.inc new file mode 100644 index 0000000..3da32e1 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_explicit_weak_2.inc @@ -0,0 +1,9 @@ +<?php + +declare(strict_types=0); + +function takes_int(int $x) { + echo "Success!"; +} + +takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/type_declarations/strict_include_weak.phpt b/Zend/tests/type_declarations/strict_include_weak.phpt new file mode 100644 index 0000000..ce29db7 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_weak.phpt @@ -0,0 +1,14 @@ +--TEST-- +strict_types=1 code including strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's implicitly weak +require 'strict_include_weak_2.inc'; + +// calls within that file should stay weak, despite being included by strict file +?> +--EXPECTF-- +Success! diff --git a/Zend/tests/type_declarations/strict_include_weak_2.inc b/Zend/tests/type_declarations/strict_include_weak_2.inc new file mode 100644 index 0000000..d4ee8a8 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_weak_2.inc @@ -0,0 +1,9 @@ +<?php + +// implicitly weak code + +function takes_int(int $x) { + echo "Success!"; +} + +takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/type_declarations/strict_nested.phpt b/Zend/tests/type_declarations/strict_nested.phpt new file mode 100644 index 0000000..2001f8b --- /dev/null +++ b/Zend/tests/type_declarations/strict_nested.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test nested function calls in strict_types=0 and strict_types=1 modes +--FILE-- +<?php + +function takes_int(int $x) { + global $errored; + if ($errored) { + echo "Failure!", PHP_EOL; + $errored = FALSE; + } else { + echo "Success!", PHP_EOL; + } +} + +declare(strict_types=1) { + function strict_calls_takes_int() { + takes_int(1.0); // should fail, strict mode + } + + class StrictTakesIntCaller { + public function call() { + takes_int(1.0); // should fail, strict mode + } + } +} + +declare(strict_types=0) { + function explicit_weak_calls_takes_int() { + takes_int(1.0); // should succeed, weak mode + } + + class ExplicitWeakTakesIntCaller { + public function call() { + takes_int(1.0); // should succeed, weak mode + } + } +} + + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/weak_call_strict.phpt b/Zend/tests/type_declarations/weak_call_strict.phpt new file mode 100644 index 0000000..b0ea78c --- /dev/null +++ b/Zend/tests/type_declarations/weak_call_strict.phpt @@ -0,0 +1,16 @@ +--TEST-- +strict_types=0 code calling strict_types=1 code +--FILE-- +<?php + +// implicitly strict_types=0 + +// file with strict_types=1 +require 'weak_call_strict_2.inc'; + +// Will succeed: Function was declared in strict mode, but that does not matter +// This file uses weak mode, so the call is weak, and float accepted for int +function_declared_in_strict_mode(1.0); +?> +--EXPECT-- +Success! diff --git a/Zend/tests/type_declarations/weak_call_strict_2.inc b/Zend/tests/type_declarations/weak_call_strict_2.inc new file mode 100644 index 0000000..fe2a17f --- /dev/null +++ b/Zend/tests/type_declarations/weak_call_strict_2.inc @@ -0,0 +1,7 @@ +<?php + +declare(strict_types=1); + +function function_declared_in_strict_mode(int $x) { + echo "Success!"; +} diff --git a/Zend/tests/type_declarations/weak_explicit_call_strict.phpt b/Zend/tests/type_declarations/weak_explicit_call_strict.phpt new file mode 100644 index 0000000..b07cef5 --- /dev/null +++ b/Zend/tests/type_declarations/weak_explicit_call_strict.phpt @@ -0,0 +1,16 @@ +--TEST-- +Explicitly strict_types=0 code calling strict_types=1 code +--FILE-- +<?php + +declare(strict_types=0); + +// file with strict_types=1 +require 'weak_call_strict_2.inc'; + +// Will succeed: Function was declared in strict mode, but that does not matter +// This file uses weak mode, so the call is weak, and float accepted for int +function_declared_in_strict_mode(1.0); +?> +--EXPECT-- +Success! diff --git a/Zend/tests/type_declarations/weak_include_strict.phpt b/Zend/tests/type_declarations/weak_include_strict.phpt new file mode 100644 index 0000000..e49485d --- /dev/null +++ b/Zend/tests/type_declarations/weak_include_strict.phpt @@ -0,0 +1,19 @@ +--TEST-- +strict_types=0 code including strict_types=1 code +--FILE-- +<?php + +// implicitly weak code + +// file with strict_types=1 +require 'weak_include_strict_2.inc'; + +// calls within that file should stay strict, despite being included by weak file +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 +Stack trace: +#0 %s(%d): takes_int(1) +#1 %s(%d): require('%s') +#2 {main} + thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/type_declarations/weak_include_strict_2.inc b/Zend/tests/type_declarations/weak_include_strict_2.inc new file mode 100644 index 0000000..8acfc03 --- /dev/null +++ b/Zend/tests/type_declarations/weak_include_strict_2.inc @@ -0,0 +1,9 @@ +<?php + +declare(strict_types=1); + +function takes_int(int $x) { + echo "Success!"; +} + +takes_int(1.0); // fails in strict mode diff --git a/Zend/tests/typehints/add_return_type.phpt b/Zend/tests/typehints/add_return_type.phpt deleted file mode 100644 index de8a17d..0000000 --- a/Zend/tests/typehints/add_return_type.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Adding a return type during inheritance is allowed ---FILE-- -<?php - -interface One { - public function a(); - public function b(); - public function c(); - public function d(); -} - -interface Two extends One { - public function a() : stdClass; - public function c() : callable; - public function b() : array; - public function d() : int; -} - -?> -Done ---EXPECT-- -Done diff --git a/Zend/tests/typehints/default_boolean_hint_values.phpt b/Zend/tests/typehints/default_boolean_hint_values.phpt deleted file mode 100644 index 6ba2628..0000000 --- a/Zend/tests/typehints/default_boolean_hint_values.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Default values for boolean hints should work ---FILE-- -<?php - -function foo(bool $x = true, bool $y = false) { - var_dump($x, $y); -} - - - -foo(); -?> ---EXPECTF-- -bool(true) -bool(false) diff --git a/Zend/tests/typehints/explicit_weak_include_strict.phpt b/Zend/tests/typehints/explicit_weak_include_strict.phpt deleted file mode 100644 index fb53d8c..0000000 --- a/Zend/tests/typehints/explicit_weak_include_strict.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -explicitly strict_types=0 code including strict_types=1 code ---FILE-- -<?php - -declare(strict_types=0); - -// file with strict_types=1 -require 'weak_include_strict_2.inc'; - -// calls within that file should stay strict, despite being included by weak file -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 -Stack trace: -#0 %s(%d): takes_int(1) -#1 %s(%d): require('%s') -#2 {main} - thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt b/Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt deleted file mode 100644 index 3bacf82..0000000 --- a/Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Inexistent class as typehint receiving scalar argument ---FILE-- -<?php - -function foo(bar $ex) {} -foo(null); - -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be an instance of bar, null given, called in %s on line %d and defined in %s:%d -Stack trace: -#0 %s(%d): foo(NULL) -#1 {main} - thrown in %s on line %d - diff --git a/Zend/tests/typehints/internal_function_strict_mode.phpt b/Zend/tests/typehints/internal_function_strict_mode.phpt deleted file mode 100644 index f501c2b..0000000 --- a/Zend/tests/typehints/internal_function_strict_mode.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -Scalar type hint - internal function strict mode ---FILE-- -<?php -declare(strict_types=1); - -echo "*** Trying Ord With Integer" . PHP_EOL; -try { - var_dump(ord(1)); -} catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; -} - -echo "*** Trying Array Map With Invalid Callback" . PHP_EOL; -try { - array_map([null, "bar"], []); -} catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; -} - -echo "*** Trying Strlen With Float" . PHP_EOL; -try { - var_dump(strlen(1.5)); -} catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; -} - -?> ---EXPECTF-- -*** Trying Ord With Integer -*** Caught ord() expects parameter 1 to be string, integer given -*** Trying Array Map With Invalid Callback -*** Caught array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object -*** Trying Strlen With Float -*** Caught strlen() expects parameter 1 to be string, float given \ No newline at end of file diff --git a/Zend/tests/typehints/return_separation.phpt b/Zend/tests/typehints/return_separation.phpt deleted file mode 100644 index 7e9d095..0000000 --- a/Zend/tests/typehints/return_separation.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Return values are separated for references with rc=1 ---FILE-- -<?php - -function test1() : array { - $array = []; - $ref =& $array; - unset($ref); - return $array; -} - -function test2() : string { - $int = 42; - $ref =& $int; - unset($ref); - return $int; -} - -var_dump(test1()); -var_dump(test2()); - -?> ---EXPECT-- -array(0) { -} -string(2) "42" diff --git a/Zend/tests/typehints/scalar_basic.phpt b/Zend/tests/typehints/scalar_basic.phpt deleted file mode 100644 index f27dc2b..0000000 --- a/Zend/tests/typehints/scalar_basic.phpt +++ /dev/null @@ -1,277 +0,0 @@ ---TEST-- -Scalar type hint basics ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo PHP_EOL . "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (\TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} -echo PHP_EOL . "Done"; -?> ---EXPECTF-- - -Testing 'int' typehint: - -*** Trying int(1) -int(1) - -*** Trying string(1) "1" -int(1) - -*** Trying float(1) -int(1) - -*** Trying float(1.5) -int(1) - -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -int(1) - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying int(%d) -int(%d) - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying bool(true) -int(1) - -*** Trying bool(false) -int(0) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying int(1) -float(1) - -*** Trying string(1) "1" -float(1) - -*** Trying float(1) -float(1) - -*** Trying float(1.5) -float(1.5) - -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -float(1) - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying int(%d) -float(%s) - -*** Trying float(NAN) -float(NAN) - -*** Trying bool(true) -float(1) - -*** Trying bool(false) -float(0) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying int(1) -string(1) "1" - -*** Trying string(1) "1" -string(1) "1" - -*** Trying float(1) -string(1) "1" - -*** Trying float(1.5) -string(3) "1.5" - -*** Trying string(2) "1a" -string(2) "1a" - -*** Trying string(1) "a" -string(1) "a" - -*** Trying string(0) "" -string(0) "" - -*** Trying int(%d) -string(%d) "%d" - -*** Trying float(NAN) -string(3) "NAN" - -*** Trying bool(true) -string(1) "1" - -*** Trying bool(false) -string(0) "" - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -string(6) "foobar" - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying int(1) -bool(true) - -*** Trying string(1) "1" -bool(true) - -*** Trying float(1) -bool(true) - -*** Trying float(1.5) -bool(true) - -*** Trying string(2) "1a" -bool(true) - -*** Trying string(1) "a" -bool(true) - -*** Trying string(0) "" -bool(false) - -*** Trying int(%d) -bool(true) - -*** Trying float(NAN) -bool(true) - -*** Trying bool(true) -bool(true) - -*** Trying bool(false) -bool(false) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_constant_defaults.phpt b/Zend/tests/typehints/scalar_constant_defaults.phpt deleted file mode 100644 index 4441022..0000000 --- a/Zend/tests/typehints/scalar_constant_defaults.phpt +++ /dev/null @@ -1,83 +0,0 @@ ---TEST-- -Scalar type hint - default via constants ---FILE-- -<?php - -const INT_VAL = 10; -const FLOAT_VAL = 10.5; -const STRING_VAL = "this is a test"; -const INT_ADD_VAL = 10 + 15; -const FLOAT_ADD_VAL = 10.5 + 0.2; -const STRING_ADD_VAL = "this" . " is a test"; -const NULL_VAL = null; - -function int_val(int $a = INT_VAL): int { - return $a; -} - -function float_val(float $a = FLOAT_VAL): float { - return $a; -} - -function string_val(string $a = STRING_VAL): string { - return $a; -} - -function int_add_val(int $a = INT_ADD_VAL): int { - return $a; -} - -function float_add_val(float $a = FLOAT_ADD_VAL): float { - return $a; -} - -function string_add_val(string $a = STRING_ADD_VAL): string { - return $a; -} - -function int_val_default_null(int $a = NULL_VAL) { - return $a; -} - -echo "Testing int val" . PHP_EOL; -var_dump(int_val()); - -echo "Testing float val" . PHP_EOL; -var_dump(float_val()); - -echo "Testing string val" . PHP_EOL; -var_dump(string_val()); - -echo "Testing int add val" . PHP_EOL; -var_dump(int_add_val()); - -echo "Testing float add val" . PHP_EOL; -var_dump(float_add_val()); - -echo "Testing string add val" . PHP_EOL; -var_dump(string_add_val()); - -echo "Testing int with default null constant" . PHP_EOL; -var_dump(int_val_default_null()); - -echo "Testing int with null null constant" . PHP_EOL; -var_dump(int_val_default_null(null)); - -?> ---EXPECTF-- -Testing int val -int(10) -Testing float val -float(10.5) -Testing string val -string(14) "this is a test" -Testing int add val -int(25) -Testing float add val -float(10.7) -Testing string add val -string(14) "this is a test" -Testing int with default null constant -NULL -Testing int with null null constant -NULL \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_constant_defaults_error.phpt b/Zend/tests/typehints/scalar_constant_defaults_error.phpt deleted file mode 100644 index f341d20..0000000 --- a/Zend/tests/typehints/scalar_constant_defaults_error.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Scalar type hint - default via constants - error condition ---FILE-- -<?php - -const STRING_VAL = "test"; - -function int_val(int $a = STRING_VAL): int { - return $a; -} - -var_dump(int_val()); - -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to int_val() must be of the type integer, string given, called in %s on line %d and defined in %s:%d -Stack trace: -#0 %s(%d): int_val() -#1 {main} - thrown in %s on line %d \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt b/Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt deleted file mode 100644 index b1aab43..0000000 --- a/Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Float type hint should allow an integer as default even with strict types ---FILE-- -<?php - -declare(strict_types=1); - -function test(float $arg = 0) -{ - var_dump($arg); -} - -test(); - -?> ---EXPECT-- -float(0) diff --git a/Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt b/Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt deleted file mode 100644 index ab32066..0000000 --- a/Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Float type hint should allow an integer as default ---FILE-- -<?php - -function test(float $arg = 0) -{ - var_dump($arg); -} - -test(); - -?> ---EXPECT-- -float(0) diff --git a/Zend/tests/typehints/scalar_float_with_invalid_default.phpt b/Zend/tests/typehints/scalar_float_with_invalid_default.phpt deleted file mode 100644 index 6b67985..0000000 --- a/Zend/tests/typehints/scalar_float_with_invalid_default.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Float type hint should not allow invalid types as default ---FILE-- -<?php - -function test(float $arg = true) -{ - var_dump($arg); -} - -test(); - -?> ---EXPECTF-- - -Fatal error: Default value for parameters with a float type hint can only be float, integer, or NULL in %s on line %d diff --git a/Zend/tests/typehints/scalar_none.phpt b/Zend/tests/typehints/scalar_none.phpt deleted file mode 100644 index 5a98377..0000000 --- a/Zend/tests/typehints/scalar_none.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Scalar type hint missing parameters ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; }, - 'int nullable' => function (int $i = NULL) { return $i; }, - 'float nullable' => function (float $f = NULL) { return $f; }, - 'string nullable' => function (string $s = NULL) { return $s; }, - 'bool nullable' => function (bool $b = NULL) { return $b; } -]; - -foreach ($functions as $type => $function) { - echo "Testing $type:", PHP_EOL; - try { - var_dump($function()); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } -} -echo PHP_EOL . "Done"; ---EXPECTF-- -Testing int: -*** Caught Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d -Testing float: -*** Caught Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d -Testing string: -*** Caught Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d -Testing bool: -*** Caught Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d -Testing int nullable: -NULL -Testing float nullable: -NULL -Testing string nullable: -NULL -Testing bool nullable: -NULL - -Done diff --git a/Zend/tests/typehints/scalar_null.phpt b/Zend/tests/typehints/scalar_null.phpt deleted file mode 100644 index f409e34..0000000 --- a/Zend/tests/typehints/scalar_null.phpt +++ /dev/null @@ -1,56 +0,0 @@ ---TEST-- -Scalar type hint nullability ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; }, - 'int nullable' => function (int $i = NULL) { return $i; }, - 'float nullable' => function (float $f = NULL) { return $f; }, - 'string nullable' => function (string $s = NULL) { return $s; }, - 'bool nullable' => function (bool $b = NULL) { return $b; } -]; - -foreach ($functions as $type => $function) { - echo "Testing $type:", PHP_EOL; - try { - var_dump($function(null)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing int: -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d -Testing float: -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d -Testing string: -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d -Testing bool: -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d -Testing int nullable: -NULL -Testing float nullable: -NULL -Testing string nullable: -NULL -Testing bool nullable: -NULL - -Done diff --git a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt b/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt deleted file mode 100644 index d850912..0000000 --- a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Scalar type hint - disallow relative typehints ---FILE-- -<?php - -function foo(bar\int $a): int { - return $a; -} - -foo(10); - -?> ---EXPECTF-- -Fatal error: Cannot use 'bar\int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved2.phpt b/Zend/tests/typehints/scalar_reserved2.phpt deleted file mode 100644 index 01f36fd..0000000 --- a/Zend/tests/typehints/scalar_reserved2.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (2) ---FILE-- -<?php - -class int {} ---EXPECTF-- -Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved2_class_alias.phpt b/Zend/tests/typehints/scalar_reserved2_class_alias.phpt deleted file mode 100644 index 02d6bb4..0000000 --- a/Zend/tests/typehints/scalar_reserved2_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (2) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "int"); ---EXPECTF-- -Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved2_use.phpt b/Zend/tests/typehints/scalar_reserved2_use.phpt deleted file mode 100644 index e61db5c..0000000 --- a/Zend/tests/typehints/scalar_reserved2_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (2) - use ---FILE-- -<?php - -use foobar as int; ---EXPECTF-- -Fatal error: Cannot use foobar as int because 'int' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved3.phpt b/Zend/tests/typehints/scalar_reserved3.phpt deleted file mode 100644 index 425365b..0000000 --- a/Zend/tests/typehints/scalar_reserved3.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (3) ---FILE-- -<?php - -class float {} ---EXPECTF-- -Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved3_class_alias.phpt b/Zend/tests/typehints/scalar_reserved3_class_alias.phpt deleted file mode 100644 index 39c2e2a..0000000 --- a/Zend/tests/typehints/scalar_reserved3_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (3) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "float"); ---EXPECTF-- -Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved3_use.phpt b/Zend/tests/typehints/scalar_reserved3_use.phpt deleted file mode 100644 index 23be15e..0000000 --- a/Zend/tests/typehints/scalar_reserved3_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (3) - use ---FILE-- -<?php - -use foobar as float; ---EXPECTF-- -Fatal error: Cannot use foobar as float because 'float' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved4.phpt b/Zend/tests/typehints/scalar_reserved4.phpt deleted file mode 100644 index 5a190ce..0000000 --- a/Zend/tests/typehints/scalar_reserved4.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (4) ---FILE-- -<?php - -class string {} ---EXPECTF-- -Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved4_class_alias.phpt b/Zend/tests/typehints/scalar_reserved4_class_alias.phpt deleted file mode 100644 index ffaf934..0000000 --- a/Zend/tests/typehints/scalar_reserved4_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (4) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "string"); ---EXPECTF-- -Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved4_use.phpt b/Zend/tests/typehints/scalar_reserved4_use.phpt deleted file mode 100644 index 05a2ea1..0000000 --- a/Zend/tests/typehints/scalar_reserved4_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (4) - use ---FILE-- -<?php - -use foobar as string; ---EXPECTF-- -Fatal error: Cannot use foobar as string because 'string' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved6.phpt b/Zend/tests/typehints/scalar_reserved6.phpt deleted file mode 100644 index 1dee41f..0000000 --- a/Zend/tests/typehints/scalar_reserved6.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (6) ---FILE-- -<?php - -class bool {} ---EXPECTF-- -Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved6_class_alias.phpt b/Zend/tests/typehints/scalar_reserved6_class_alias.phpt deleted file mode 100644 index fd3c328..0000000 --- a/Zend/tests/typehints/scalar_reserved6_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (6) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "bool"); ---EXPECTF-- -Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved6_use.phpt b/Zend/tests/typehints/scalar_reserved6_use.phpt deleted file mode 100644 index 9cb7857..0000000 --- a/Zend/tests/typehints/scalar_reserved6_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (6) - use ---FILE-- -<?php - -use foobar as bool; ---EXPECTF-- -Fatal error: Cannot use foobar as bool because 'bool' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved7.phpt b/Zend/tests/typehints/scalar_reserved7.phpt deleted file mode 100644 index d641d17..0000000 --- a/Zend/tests/typehints/scalar_reserved7.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (7) ---FILE-- -<?php -namespace foo; - -class int {} ---EXPECTF-- -Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt deleted file mode 100644 index 9395ec9..0000000 --- a/Zend/tests/typehints/scalar_return_basic.phpt +++ /dev/null @@ -1,216 +0,0 @@ ---TEST-- -Return scalar type hint basics ---SKIPIF-- -<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function ($i): int { return $i; }, - 'float' => function ($f): float { return $f; }, - 'string' => function ($s): string { return $s; }, - 'bool' => function ($b): bool { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: -*** Trying int(1) -int(1) -*** Trying string(1) "1" -int(1) -*** Trying float(1) -int(1) -*** Trying float(1.5) -int(1) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -int(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying int(2147483647) -int(2147483647) -*** Trying float(NAN) -*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d -*** Trying bool(true) -int(1) -*** Trying bool(false) -int(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d - -Testing 'float' typehint: -*** Trying int(1) -float(1) -*** Trying string(1) "1" -float(1) -*** Trying float(1) -float(1) -*** Trying float(1.5) -float(1.5) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -float(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying int(2147483647) -float(2147483647) -*** Trying float(NAN) -float(NAN) -*** Trying bool(true) -float(1) -*** Trying bool(false) -float(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d - -Testing 'string' typehint: -*** Trying int(1) -string(1) "1" -*** Trying string(1) "1" -string(1) "1" -*** Trying float(1) -string(1) "1" -*** Trying float(1.5) -string(3) "1.5" -*** Trying string(2) "1a" -string(2) "1a" -*** Trying string(1) "a" -string(1) "a" -*** Trying string(0) "" -string(0) "" -*** Trying int(2147483647) -string(10) "2147483647" -*** Trying float(NAN) -string(3) "NAN" -*** Trying bool(true) -string(1) "1" -*** Trying bool(false) -string(0) "" -*** Trying NULL -*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -string(6) "foobar" -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d - -Testing 'bool' typehint: -*** Trying int(1) -bool(true) -*** Trying string(1) "1" -bool(true) -*** Trying float(1) -bool(true) -*** Trying float(1.5) -bool(true) -*** Trying string(2) "1a" -bool(true) -*** Trying string(1) "a" -bool(true) -*** Trying string(0) "" -bool(false) -*** Trying int(2147483647) -bool(true) -*** Trying float(NAN) -bool(true) -*** Trying bool(true) -bool(true) -*** Trying bool(false) -bool(false) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_return_basic_64bit.phpt b/Zend/tests/typehints/scalar_return_basic_64bit.phpt deleted file mode 100644 index fc7401e..0000000 --- a/Zend/tests/typehints/scalar_return_basic_64bit.phpt +++ /dev/null @@ -1,216 +0,0 @@ ---TEST-- -Return scalar type hint basics ---SKIPIF-- -<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function ($i): int { return $i; }, - 'float' => function ($f): float { return $f; }, - 'string' => function ($s): string { return $s; }, - 'bool' => function ($b): bool { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: -*** Trying int(1) -int(1) -*** Trying string(1) "1" -int(1) -*** Trying float(1) -int(1) -*** Trying float(1.5) -int(1) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -int(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying int(9223372036854775807) -int(9223372036854775807) -*** Trying float(NAN) -*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d -*** Trying bool(true) -int(1) -*** Trying bool(false) -int(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d - -Testing 'float' typehint: -*** Trying int(1) -float(1) -*** Trying string(1) "1" -float(1) -*** Trying float(1) -float(1) -*** Trying float(1.5) -float(1.5) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -float(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) -*** Trying float(NAN) -float(NAN) -*** Trying bool(true) -float(1) -*** Trying bool(false) -float(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d - -Testing 'string' typehint: -*** Trying int(1) -string(1) "1" -*** Trying string(1) "1" -string(1) "1" -*** Trying float(1) -string(1) "1" -*** Trying float(1.5) -string(3) "1.5" -*** Trying string(2) "1a" -string(2) "1a" -*** Trying string(1) "a" -string(1) "a" -*** Trying string(0) "" -string(0) "" -*** Trying int(9223372036854775807) -string(19) "9223372036854775807" -*** Trying float(NAN) -string(3) "NAN" -*** Trying bool(true) -string(1) "1" -*** Trying bool(false) -string(0) "" -*** Trying NULL -*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -string(6) "foobar" -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d - -Testing 'bool' typehint: -*** Trying int(1) -bool(true) -*** Trying string(1) "1" -bool(true) -*** Trying float(1) -bool(true) -*** Trying float(1.5) -bool(true) -*** Trying string(2) "1a" -bool(true) -*** Trying string(1) "a" -bool(true) -*** Trying string(0) "" -bool(false) -*** Trying int(9223372036854775807) -bool(true) -*** Trying float(NAN) -bool(true) -*** Trying bool(true) -bool(true) -*** Trying bool(false) -bool(false) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict.phpt b/Zend/tests/typehints/scalar_strict.phpt deleted file mode 100644 index 59ec45a..0000000 --- a/Zend/tests/typehints/scalar_strict.phpt +++ /dev/null @@ -1,279 +0,0 @@ ---TEST-- -Scalar type hint strict mode ---SKIPIF-- -<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> ---FILE-- -<?php -declare(strict_types=1); - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo PHP_EOL . "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: - -*** Trying int(1) -int(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying int(2147483647) -int(2147483647) - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying int(1) -float(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying float(1) -float(1) - -*** Trying float(1.5) -float(1.5) - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying int(2147483647) -float(2147483647) - -*** Trying float(NAN) -float(NAN) - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying string(1) "1" -string(1) "1" - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying string(2) "1a" -string(2) "1a" - -*** Trying string(1) "a" -string(1) "a" - -*** Trying string(0) "" -string(0) "" - -*** Trying int(2147483647) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying int(2147483647) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying bool(true) -bool(true) - -*** Trying bool(false) -bool(false) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict_64bit.phpt b/Zend/tests/typehints/scalar_strict_64bit.phpt deleted file mode 100644 index 4671b07..0000000 --- a/Zend/tests/typehints/scalar_strict_64bit.phpt +++ /dev/null @@ -1,279 +0,0 @@ ---TEST-- -Scalar type hint strict mode ---SKIPIF-- -<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> ---FILE-- -<?php -declare(strict_types=1); - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo PHP_EOL . "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: - -*** Trying int(1) -int(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying int(9223372036854775807) -int(9223372036854775807) - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying int(1) -float(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying float(1) -float(1) - -*** Trying float(1.5) -float(1.5) - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) - -*** Trying float(NAN) -float(NAN) - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying string(1) "1" -string(1) "1" - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying string(2) "1a" -string(2) "1a" - -*** Trying string(1) "a" -string(1) "a" - -*** Trying string(0) "" -string(0) "" - -*** Trying int(9223372036854775807) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying int(9223372036854775807) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying bool(true) -bool(true) - -*** Trying bool(false) -bool(false) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict_basic.phpt b/Zend/tests/typehints/scalar_strict_basic.phpt deleted file mode 100644 index 15030e1..0000000 --- a/Zend/tests/typehints/scalar_strict_basic.phpt +++ /dev/null @@ -1,181 +0,0 @@ ---TEST-- -Strict scalar type hint basics ---FILE-- -<?php - -declare(strict_types=1); - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; - -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -$values = [ - 1, - 1.0, - "1", - TRUE, - FALSE, - NULL, - [], - new StdClass, - fopen("data:text/plain,foobar", "r") -]; - -function type($value) { - if (is_float($value)) { - return "float"; - } else if (is_bool($value)) { - return $value ? "true" : "false"; - } else if (is_null($value)) { - return "null"; - } else { - return gettype($value); - } -} - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - $errored = false; - echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL; - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: - -*** Trying integer value -int(1) - -*** Trying float value -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying string value -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying true value -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying false value -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying integer value -float(1) - -*** Trying float value -float(1) - -*** Trying string value -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying true value -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying false value -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying integer value -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying float value -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying string value -string(1) "1" - -*** Trying true value -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying false value -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying integer value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying float value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying string value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying true value -bool(true) - -*** Trying false value -bool(false) - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt deleted file mode 100644 index 2a2b3e6..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Test strict declaration being first operation only ---FILE-- -<?php - -function takes_int(int $x) { - global $errored; - if ($errored) { - echo "Failure!", PHP_EOL; - $errored = FALSE; - } else { - echo "Success!", PHP_EOL; - } -} - -?> -<?php - -declare(strict_types=1); -var_dump(takes_int(32)); - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt deleted file mode 100644 index 09ac111..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 002 ---FILE-- -<?php - -namespace Foo; - -declare(strict_types=1); - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt deleted file mode 100644 index 6ec5b59..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 003 ---FILE-- -hi<?php - -declare(strict_types=1); -var_dump(strlen(32)); - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt deleted file mode 100644 index 6000324..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 004 ---FILE-- -<?php -declare(strict_types=1); - -namespace Foo { - function add1(int $arg): int { - return $arg + 1; - } -} - -namespace { - var_dump(Foo\add1(123)); -} ---EXPECT-- -int(124) diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt deleted file mode 100644 index 8611a20..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 005 ---FILE-- -<?php - -declare(strict_types=1); - -namespace Foo; - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -int(3) \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt deleted file mode 100644 index 2af05b6..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 006 ---SKIPIF-- -<?php -if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { - die("skip Requires configure --enable-zend-multibyte option"); -} -if (!extension_loaded("mbstring")) { - die("skip Requires mbstring extension"); -} -?> ---INI-- -zend.multibyte=1 ---FILE-- -<?php -declare(encoding="UTF-8"); -declare(strict_types=1); - -namespace Foo; - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -int(3) \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt deleted file mode 100644 index 3e4c693..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 007 ---SKIPIF-- -<?php -if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { - die("skip Requires configure --enable-zend-multibyte option"); -} -if (!extension_loaded("mbstring")) { - die("skip Requires mbstring extension"); -} -?> ---INI-- -zend.multibyte=1 ---FILE-- -<?php -declare(strict_types=1); -declare(encoding="ISO-8859-1"); - -namespace Foo; - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -int(3) \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt deleted file mode 100644 index 87a09af..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Test strict declaration block declaration 008 ---FILE-- -<?php -declare(strict_types=1) { - var_dump(strlen("abc")); -} - -?> ---EXPECTF-- -Fatal error: strict_types declaration must not use block mode in %s on line %d \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_weak_reference.phpt b/Zend/tests/typehints/scalar_weak_reference.phpt deleted file mode 100644 index f397cea..0000000 --- a/Zend/tests/typehints/scalar_weak_reference.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -Weak scalar type hints, with references ---FILE-- -<?php - -// implicitly weak mode code - -function to_int(int &$x) {} -function to_float(float &$x) {} -function to_string(string &$x) {} -function to_bool(bool &$x) {} - -$x = 1.0; -var_dump($x); -to_int($x); // because $x is by-reference, the weak type hint converts it -var_dump($x); -to_float($x); -var_dump($x); -to_string($x); -var_dump($x); -to_bool($x); -var_dump($x); -?> ---EXPECT-- -float(1) -int(1) -float(1) -string(1) "1" -bool(true) diff --git a/Zend/tests/typehints/self_on_closure_in_method.phpt b/Zend/tests/typehints/self_on_closure_in_method.phpt deleted file mode 100644 index 2d5bd82..0000000 --- a/Zend/tests/typehints/self_on_closure_in_method.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -self return type on closure in a method ---FILE-- -<?php - -class A { - public function test() { - return function() : self { - return $this; - }; - } -} - -var_dump((new A)->test()()); - -?> ---EXPECT-- -object(A)#1 (0) { -} diff --git a/Zend/tests/typehints/strict_call_weak.phpt b/Zend/tests/typehints/strict_call_weak.phpt deleted file mode 100644 index e3a606e..0000000 --- a/Zend/tests/typehints/strict_call_weak.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -strict_types=1 code calling strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's implicitly weak -require 'strict_call_weak_2.inc'; - -// Will succeed: Function was declared in weak mode, but that does not matter -// This file uses strict mode, so the call is strict, and float denied for int -function_declared_in_weak_mode(1.0); -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak.php on line 10 and defined in %sstrict_call_weak_2.inc:5 -Stack trace: -#0 %s(%d): function_declared_in_weak_mode(1) -#1 {main} - thrown in %sstrict_call_weak_2.inc on line 5 - diff --git a/Zend/tests/typehints/strict_call_weak_2.inc b/Zend/tests/typehints/strict_call_weak_2.inc deleted file mode 100644 index cba5512..0000000 --- a/Zend/tests/typehints/strict_call_weak_2.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -// implicitly weak code - -function function_declared_in_weak_mode(int $x) { - echo "Success!"; -} diff --git a/Zend/tests/typehints/strict_call_weak_explicit.phpt b/Zend/tests/typehints/strict_call_weak_explicit.phpt deleted file mode 100644 index 22c5b43..0000000 --- a/Zend/tests/typehints/strict_call_weak_explicit.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -strict_types=1 code calling explicitly strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's explicitly weak -require 'strict_call_weak_explicit_2.inc'; - -// Will succeed: Function was declared in weak mode, but that does not matter -// This file uses strict mode, so the call is strict, and float denied for int -function_declared_in_weak_mode(1.0); -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak_explicit.php on line 10 and defined in %sstrict_call_weak_explicit_2.inc:5 -Stack trace: -#0 %s(%d): function_declared_in_weak_mode(1) -#1 {main} - thrown in %sstrict_call_weak_explicit_2.inc on line 5 - diff --git a/Zend/tests/typehints/strict_call_weak_explicit_2.inc b/Zend/tests/typehints/strict_call_weak_explicit_2.inc deleted file mode 100644 index d26c847..0000000 --- a/Zend/tests/typehints/strict_call_weak_explicit_2.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -declare(strict_types=0); - -function function_declared_in_weak_mode(int $x) { - echo "Success!"; -} diff --git a/Zend/tests/typehints/strict_include_explicit_weak.phpt b/Zend/tests/typehints/strict_include_explicit_weak.phpt deleted file mode 100644 index a42d633..0000000 --- a/Zend/tests/typehints/strict_include_explicit_weak.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -strict_types=1 code including explicitly strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's explicitly weak -require 'strict_include_explicit_weak_2.inc'; - -// calls within that file should stay weak, despite being included by strict fille -?> ---EXPECTF-- -Success! diff --git a/Zend/tests/typehints/strict_include_explicit_weak_2.inc b/Zend/tests/typehints/strict_include_explicit_weak_2.inc deleted file mode 100644 index 3da32e1..0000000 --- a/Zend/tests/typehints/strict_include_explicit_weak_2.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -declare(strict_types=0); - -function takes_int(int $x) { - echo "Success!"; -} - -takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/typehints/strict_include_weak.phpt b/Zend/tests/typehints/strict_include_weak.phpt deleted file mode 100644 index ce29db7..0000000 --- a/Zend/tests/typehints/strict_include_weak.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -strict_types=1 code including strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's implicitly weak -require 'strict_include_weak_2.inc'; - -// calls within that file should stay weak, despite being included by strict file -?> ---EXPECTF-- -Success! diff --git a/Zend/tests/typehints/strict_include_weak_2.inc b/Zend/tests/typehints/strict_include_weak_2.inc deleted file mode 100644 index d4ee8a8..0000000 --- a/Zend/tests/typehints/strict_include_weak_2.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -// implicitly weak code - -function takes_int(int $x) { - echo "Success!"; -} - -takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/typehints/strict_nested.phpt b/Zend/tests/typehints/strict_nested.phpt deleted file mode 100644 index 2001f8b..0000000 --- a/Zend/tests/typehints/strict_nested.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -Test nested function calls in strict_types=0 and strict_types=1 modes ---FILE-- -<?php - -function takes_int(int $x) { - global $errored; - if ($errored) { - echo "Failure!", PHP_EOL; - $errored = FALSE; - } else { - echo "Success!", PHP_EOL; - } -} - -declare(strict_types=1) { - function strict_calls_takes_int() { - takes_int(1.0); // should fail, strict mode - } - - class StrictTakesIntCaller { - public function call() { - takes_int(1.0); // should fail, strict mode - } - } -} - -declare(strict_types=0) { - function explicit_weak_calls_takes_int() { - takes_int(1.0); // should succeed, weak mode - } - - class ExplicitWeakTakesIntCaller { - public function call() { - takes_int(1.0); // should succeed, weak mode - } - } -} - - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/weak_call_strict.phpt b/Zend/tests/typehints/weak_call_strict.phpt deleted file mode 100644 index b0ea78c..0000000 --- a/Zend/tests/typehints/weak_call_strict.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -strict_types=0 code calling strict_types=1 code ---FILE-- -<?php - -// implicitly strict_types=0 - -// file with strict_types=1 -require 'weak_call_strict_2.inc'; - -// Will succeed: Function was declared in strict mode, but that does not matter -// This file uses weak mode, so the call is weak, and float accepted for int -function_declared_in_strict_mode(1.0); -?> ---EXPECT-- -Success! diff --git a/Zend/tests/typehints/weak_call_strict_2.inc b/Zend/tests/typehints/weak_call_strict_2.inc deleted file mode 100644 index fe2a17f..0000000 --- a/Zend/tests/typehints/weak_call_strict_2.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -declare(strict_types=1); - -function function_declared_in_strict_mode(int $x) { - echo "Success!"; -} diff --git a/Zend/tests/typehints/weak_explicit_call_strict.phpt b/Zend/tests/typehints/weak_explicit_call_strict.phpt deleted file mode 100644 index b07cef5..0000000 --- a/Zend/tests/typehints/weak_explicit_call_strict.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Explicitly strict_types=0 code calling strict_types=1 code ---FILE-- -<?php - -declare(strict_types=0); - -// file with strict_types=1 -require 'weak_call_strict_2.inc'; - -// Will succeed: Function was declared in strict mode, but that does not matter -// This file uses weak mode, so the call is weak, and float accepted for int -function_declared_in_strict_mode(1.0); -?> ---EXPECT-- -Success! diff --git a/Zend/tests/typehints/weak_include_strict.phpt b/Zend/tests/typehints/weak_include_strict.phpt deleted file mode 100644 index e49485d..0000000 --- a/Zend/tests/typehints/weak_include_strict.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -strict_types=0 code including strict_types=1 code ---FILE-- -<?php - -// implicitly weak code - -// file with strict_types=1 -require 'weak_include_strict_2.inc'; - -// calls within that file should stay strict, despite being included by weak file -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 -Stack trace: -#0 %s(%d): takes_int(1) -#1 %s(%d): require('%s') -#2 {main} - thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/typehints/weak_include_strict_2.inc b/Zend/tests/typehints/weak_include_strict_2.inc deleted file mode 100644 index 8acfc03..0000000 --- a/Zend/tests/typehints/weak_include_strict_2.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -declare(strict_types=1); - -function takes_int(int $x) { - echo "Success!"; -} - -takes_int(1.0); // fails in strict mode diff --git a/Zend/tests/variadic/typehint_error.phpt b/Zend/tests/variadic/typehint_error.phpt index 26842bb..153161a 100644 --- a/Zend/tests/variadic/typehint_error.phpt +++ b/Zend/tests/variadic/typehint_error.phpt @@ -1,5 +1,5 @@ --TEST-- -Variadic arguments enforce typehints +Variadic arguments enforce types --FILE-- <?php diff --git a/Zend/tests/variadic/typehint_suppressed_error.phpt b/Zend/tests/variadic/typehint_suppressed_error.phpt index 24109e0..ef217b2 100644 --- a/Zend/tests/variadic/typehint_suppressed_error.phpt +++ b/Zend/tests/variadic/typehint_suppressed_error.phpt @@ -1,5 +1,5 @@ --TEST-- -Error suppression for typehints on variadic arguments works +Error suppression for types on variadic arguments works --FILE-- <?php diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f65f2ed..d3e17d0 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4416,7 +4416,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */ zend_arg_info *arg_infos; if (return_type_ast) { - /* Use op_array->arg_info[-1] for return type hinting */ + /* Use op_array->arg_info[-1] for return type */ arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children + 1, 0); arg_infos->name = NULL; arg_infos->pass_by_reference = (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0; @@ -4525,31 +4525,31 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */ && !Z_CONSTANT(default_node.u.constant) ) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with array type hint can only be an array or NULL"); + "with array type can only be an array or NULL"); } } else if (arg_info->type_hint == IS_CALLABLE && default_ast) { if (!has_null_default && !Z_CONSTANT(default_node.u.constant)) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with callable type hint can only be NULL"); + "with callable type can only be NULL"); } } } else { if (default_ast && !has_null_default && !Z_CONSTANT(default_node.u.constant)) { if (arg_info->class_name) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with a class type hint can only be NULL"); + "with a class type can only be NULL"); } else switch (arg_info->type_hint) { case IS_DOUBLE: if (Z_TYPE(default_node.u.constant) != IS_DOUBLE && Z_TYPE(default_node.u.constant) != IS_LONG) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with a float type hint can only be float, integer, or NULL"); + "with a float type can only be float, integer, or NULL"); } break; default: if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with a %s type hint can only be %s or NULL", + "with a %s type can only be %s or NULL", zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint)); } break; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index b777a0b..992d75c 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -261,7 +261,7 @@ typedef struct _zend_try_catch_element { /* class has magic methods __get/__set/__unset/__isset that use guards */ #define ZEND_ACC_USE_GUARDS 0x1000000 -/* function has arguments with type hinting */ +/* function has typed arguments */ #define ZEND_ACC_HAS_TYPE_HINTS 0x10000000 /* op_array has finally blocks */ @@ -270,7 +270,7 @@ typedef struct _zend_try_catch_element { /* internal function is allocated at arena */ #define ZEND_ACC_ARENA_ALLOCATED 0x20000000 -/* Function has a return type hint (or class has such non-private function) */ +/* Function has a return type (or class has such non-private function) */ #define ZEND_ACC_HAS_RETURN_TYPE 0x40000000 /* op_array uses strict mode types */ @@ -319,7 +319,7 @@ typedef struct _zend_arg_info { /* the following structure repeats the layout of zend_internal_arg_info, * but its fields have different meaning. It's used as the first element of * arg_info array to define properties of internal functions. - * It's also used for return type hinting. + * It's also used for the return type. */ typedef struct _zend_internal_function_info { zend_uintptr_t required_num_args; diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 73b67f5..6f897ab 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -170,7 +170,7 @@ char *zend_visibility_string(uint32_t fn_flags) /* {{{ */ static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_info *fe_arg_info, const zend_function *proto, zend_arg_info *proto_arg_info) /* {{{ */ { if (ZEND_LOG_XOR(fe_arg_info->class_name, proto_arg_info->class_name)) { - /* Only one has a type hint and the other one doesn't */ + /* Only one has a type declaration and the other one doesn't */ return 0; } @@ -239,7 +239,7 @@ static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_inf } if (fe_arg_info->type_hint != proto_arg_info->type_hint) { - /* Incompatible type hint */ + /* Incompatible type */ return 0; } diff --git a/tests/lang/type_hints_003.phpt b/tests/lang/type_hints_003.phpt index 0ef3e35..2b536d0 100644 --- a/tests/lang/type_hints_003.phpt +++ b/tests/lang/type_hints_003.phpt @@ -1,5 +1,5 @@ --TEST-- -ZE2 type hinting +ZE2 type --SKIPIF-- <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> --FILE-- @@ -11,4 +11,4 @@ class T { ?> --EXPECTF-- -Fatal error: Default value for parameters with a class type hint can only be NULL in %stype_hints_003.php on line 3 +Fatal error: Default value for parameters with a class type can only be NULL in %stype_hints_003.php on line 3
diff --git a/Zend/tests/array_type_hint_001.phpt b/Zend/tests/array_type_hint_001.phpt deleted file mode 100644 index 2b473c5..0000000 --- a/Zend/tests/array_type_hint_001.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Array type hint ---FILE-- -<?php -function foo(array $a) { - echo count($a)."\n"; -} - -foo(array(1,2,3)); -foo(123); -?> ---EXPECTF-- -3 - -Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type array, integer given, called in %sarray_type_hint_001.php on line 7 and defined in %sarray_type_hint_001.php:2 -Stack trace: -#0 %s(%d): foo(123) -#1 {main} - thrown in %sarray_type_hint_001.php on line 2 diff --git a/Zend/tests/bug42802.phpt b/Zend/tests/bug42802.phpt index 3b00408..ebfb528 100644 --- a/Zend/tests/bug42802.phpt +++ b/Zend/tests/bug42802.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #42802 (Namespace not supported in typehints) +Bug #42802 (Namespace not supported in types) --FILE-- <?php namespace foo; diff --git a/Zend/tests/bug69767.phpt b/Zend/tests/bug69767.phpt index cf4d4e7..9458546 100644 --- a/Zend/tests/bug69767.phpt +++ b/Zend/tests/bug69767.phpt @@ -5,4 +5,4 @@ Bug #69767 (Default parameter value with wrong type segfaults) function foo(String $bar = 0) {} ?> --EXPECTF-- -Fatal error: Default value for parameters with a string type hint can only be string or NULL in %sbug69767.php on line %d +Fatal error: Default value for parameters with a string type can only be string or NULL in %sbug69767.php on line %d diff --git a/Zend/tests/callable_type_hint_001.phpt b/Zend/tests/callable_type_hint_001.phpt deleted file mode 100644 index 5ab892c..0000000 --- a/Zend/tests/callable_type_hint_001.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -callable type hint#001 ---FILE-- -<?php - -class bar { - function baz() {} - static function foo() {} -} -function foo(callable $bar) { - var_dump($bar); -} -$closure = function () {}; - -foo("strpos"); -foo("foo"); -foo(array("bar", "baz")); -foo(array("bar", "foo")); -foo($closure); ---EXPECTF-- -string(6) "strpos" -string(3) "foo" - -Deprecated: Non-static method bar::baz() should not be called statically in %scallable_type_hint_001.php on line %d -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(3) "baz" -} -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(3) "foo" -} -object(Closure)#%d (0) { -} - diff --git a/Zend/tests/callable_type_hint_002.phpt b/Zend/tests/callable_type_hint_002.phpt deleted file mode 100644 index b1b7339..0000000 --- a/Zend/tests/callable_type_hint_002.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -callable type hint#002 - Reflection ---FILE-- -<?php - -class bar { - static function foo(callable $arg) {} -} -function foo(callable $bar) { -} -$closure = function (callable $arg) {}; - -$rf = new ReflectionFunction("foo"); -var_dump($rf->getParameters()[0]->isCallable()); - -$rm = new ReflectionMethod("bar", "foo"); -var_dump($rm->getParameters()[0]->isCallable()); - -$rc = new ReflectionFunction($closure); -var_dump($rc->getParameters()[0]->isCallable()); - -?> ---EXPECT-- -bool(true) -bool(true) -bool(true) - diff --git a/Zend/tests/callable_type_hint_003.phpt b/Zend/tests/callable_type_hint_003.phpt deleted file mode 100644 index 83f5090..0000000 --- a/Zend/tests/callable_type_hint_003.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -callable type hint#003 ---FILE-- -<?php - -function foo(callable $a, $b, callable $c) { - var_dump($a, $b, $c); -} -function bar(callable $a = null) { - var_dump($a); -} - -foo("strpos", 123, "strpos"); -bar("substr"); -?> ---EXPECT-- -string(6) "strpos" -int(123) -string(6) "strpos" -string(6) "substr" - diff --git a/Zend/tests/closure_059.phpt b/Zend/tests/closure_059.phpt index 1ee7fe6..299d8f5 100644 --- a/Zend/tests/closure_059.phpt +++ b/Zend/tests/closure_059.phpt @@ -1,5 +1,5 @@ --TEST-- -Closure 059: Closure type hinting +Closure 059: Closure type declaration --FILE-- <?php class A { diff --git a/Zend/tests/closure_with_variadic_typehint.phpt b/Zend/tests/closure_with_variadic_typehint.phpt deleted file mode 100644 index 3e91a6f..0000000 --- a/Zend/tests/closure_with_variadic_typehint.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Closure with variadic type hint ---FILE-- -<?php -$f = function (stdClass ...$a) { - var_dump($a); -}; -$f(new stdClass); -?> ---EXPECT-- -array(1) { - [0]=> - object(stdClass)#2 (0) { - } -} diff --git a/Zend/tests/errmsg_013.phpt b/Zend/tests/errmsg_013.phpt index d1f248e..327d75e 100644 --- a/Zend/tests/errmsg_013.phpt +++ b/Zend/tests/errmsg_013.phpt @@ -1,5 +1,5 @@ --TEST-- -errmsg: default value for parameters with array type hint can only be an array or NULL +errmsg: default value for parameters with array type can only be an array or NULL --FILE-- <?php @@ -11,4 +11,4 @@ class test { echo "Done\n"; ?> --EXPECTF-- -Fatal error: Default value for parameters with array type hint can only be an array or NULL in %s on line %d +Fatal error: Default value for parameters with array type can only be an array or NULL in %s on line %d diff --git a/Zend/tests/generators/get_return.phpt b/Zend/tests/generators/get_return.phpt index c996eb4..0d3e32a 100644 --- a/Zend/tests/generators/get_return.phpt +++ b/Zend/tests/generators/get_return.phpt @@ -58,7 +58,7 @@ $gen->next(); var_dump($gen->getReturn()); // Explicit value-less return also results in a NULL generator -// return value and there is no interference with type hints +// return value and there is no interference with type declarations function gen6() : Generator { return; yield 24; diff --git a/Zend/tests/ns_055.phpt b/Zend/tests/ns_055.phpt index a692e47..16e3e69 100644 --- a/Zend/tests/ns_055.phpt +++ b/Zend/tests/ns_055.phpt @@ -1,5 +1,5 @@ --TEST-- -055: typehints in namespaces +055: types in namespaces --FILE-- <?php namespace test\ns1; diff --git a/Zend/tests/return_types/internal_functions001.phpt b/Zend/tests/return_types/internal_functions001.phpt index 66c7123..fffaf54 100644 --- a/Zend/tests/return_types/internal_functions001.phpt +++ b/Zend/tests/return_types/internal_functions001.phpt @@ -1,5 +1,5 @@ --TEST-- -Return type hinting for internal functions +Return type for internal functions --SKIPIF-- <?php diff --git a/Zend/tests/return_types/internal_functions002.phpt b/Zend/tests/return_types/internal_functions002.phpt index 65838a1..7cdb2b8 100644 --- a/Zend/tests/return_types/internal_functions002.phpt +++ b/Zend/tests/return_types/internal_functions002.phpt @@ -1,5 +1,5 @@ --TEST-- -Return type hinting for internal functions 2 +Return type for internal functions 2 --SKIPIF-- <?php diff --git a/Zend/tests/return_types/reflection001.phpt b/Zend/tests/return_types/reflection001.phpt index f616504..6492ee1 100644 --- a/Zend/tests/return_types/reflection001.phpt +++ b/Zend/tests/return_types/reflection001.phpt @@ -1,5 +1,5 @@ --TEST-- -Return type hinting and Reflection::export() +Return type and Reflection::export() --SKIPIF-- <?php diff --git a/Zend/tests/type_declarations/add_return_type.phpt b/Zend/tests/type_declarations/add_return_type.phpt new file mode 100644 index 0000000..de8a17d --- /dev/null +++ b/Zend/tests/type_declarations/add_return_type.phpt @@ -0,0 +1,23 @@ +--TEST-- +Adding a return type during inheritance is allowed +--FILE-- +<?php + +interface One { + public function a(); + public function b(); + public function c(); + public function d(); +} + +interface Two extends One { + public function a() : stdClass; + public function c() : callable; + public function b() : array; + public function d() : int; +} + +?> +Done +--EXPECT-- +Done diff --git a/Zend/tests/type_declarations/array_001.phpt b/Zend/tests/type_declarations/array_001.phpt new file mode 100644 index 0000000..8fc368e --- /dev/null +++ b/Zend/tests/type_declarations/array_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +Array type declaration +--FILE-- +<?php +function foo(array $a) { + echo count($a)."\n"; +} + +foo(array(1,2,3)); +foo(123); +?> +--EXPECTF-- +3 + +Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type array, integer given, called in %s on line 7 and defined in %s:2 +Stack trace: +#0 %s(%d): foo(123) +#1 {main} + thrown in %s on line 2 diff --git a/Zend/tests/type_declarations/callable_001.phpt b/Zend/tests/type_declarations/callable_001.phpt new file mode 100644 index 0000000..0466288 --- /dev/null +++ b/Zend/tests/type_declarations/callable_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +callable type#001 +--FILE-- +<?php + +class bar { + function baz() {} + static function foo() {} +} +function foo(callable $bar) { + var_dump($bar); +} +$closure = function () {}; + +foo("strpos"); +foo("foo"); +foo(array("bar", "baz")); +foo(array("bar", "foo")); +foo($closure); +--EXPECTF-- +string(6) "strpos" +string(3) "foo" + +Deprecated: Non-static method bar::baz() should not be called statically in %s on line %d +array(2) { + [0]=> + string(3) "bar" + [1]=> + string(3) "baz" +} +array(2) { + [0]=> + string(3) "bar" + [1]=> + string(3) "foo" +} +object(Closure)#%d (0) { +} + diff --git a/Zend/tests/type_declarations/callable_002.phpt b/Zend/tests/type_declarations/callable_002.phpt new file mode 100644 index 0000000..01b6945 --- /dev/null +++ b/Zend/tests/type_declarations/callable_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +callable type#002 - Reflection +--FILE-- +<?php + +class bar { + static function foo(callable $arg) {} +} +function foo(callable $bar) { +} +$closure = function (callable $arg) {}; + +$rf = new ReflectionFunction("foo"); +var_dump($rf->getParameters()[0]->isCallable()); + +$rm = new ReflectionMethod("bar", "foo"); +var_dump($rm->getParameters()[0]->isCallable()); + +$rc = new ReflectionFunction($closure); +var_dump($rc->getParameters()[0]->isCallable()); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) + diff --git a/Zend/tests/type_declarations/callable_003.phpt b/Zend/tests/type_declarations/callable_003.phpt new file mode 100644 index 0000000..b5e722c --- /dev/null +++ b/Zend/tests/type_declarations/callable_003.phpt @@ -0,0 +1,21 @@ +--TEST-- +callable type#003 +--FILE-- +<?php + +function foo(callable $a, $b, callable $c) { + var_dump($a, $b, $c); +} +function bar(callable $a = null) { + var_dump($a); +} + +foo("strpos", 123, "strpos"); +bar("substr"); +?> +--EXPECT-- +string(6) "strpos" +int(123) +string(6) "strpos" +string(6) "substr" + diff --git a/Zend/tests/type_declarations/closure_with_variadic.phpt b/Zend/tests/type_declarations/closure_with_variadic.phpt new file mode 100644 index 0000000..acbf57f --- /dev/null +++ b/Zend/tests/type_declarations/closure_with_variadic.phpt @@ -0,0 +1,15 @@ +--TEST-- +Closure with variadic type declaration +--FILE-- +<?php +$f = function (stdClass ...$a) { + var_dump($a); +}; +$f(new stdClass); +?> +--EXPECT-- +array(1) { + [0]=> + object(stdClass)#2 (0) { + } +} diff --git a/Zend/tests/type_declarations/default_boolean_hint_values.phpt b/Zend/tests/type_declarations/default_boolean_hint_values.phpt new file mode 100644 index 0000000..6ba2628 --- /dev/null +++ b/Zend/tests/type_declarations/default_boolean_hint_values.phpt @@ -0,0 +1,16 @@ +--TEST-- +Default values for boolean hints should work +--FILE-- +<?php + +function foo(bool $x = true, bool $y = false) { + var_dump($x, $y); +} + + + +foo(); +?> +--EXPECTF-- +bool(true) +bool(false) diff --git a/Zend/tests/type_declarations/explicit_weak_include_strict.phpt b/Zend/tests/type_declarations/explicit_weak_include_strict.phpt new file mode 100644 index 0000000..fb53d8c --- /dev/null +++ b/Zend/tests/type_declarations/explicit_weak_include_strict.phpt @@ -0,0 +1,19 @@ +--TEST-- +explicitly strict_types=0 code including strict_types=1 code +--FILE-- +<?php + +declare(strict_types=0); + +// file with strict_types=1 +require 'weak_include_strict_2.inc'; + +// calls within that file should stay strict, despite being included by weak file +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 +Stack trace: +#0 %s(%d): takes_int(1) +#1 %s(%d): require('%s') +#2 {main} + thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt b/Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt new file mode 100644 index 0000000..2f6c881 --- /dev/null +++ b/Zend/tests/type_declarations/inexistent_class_hint_with_scalar_arg.phpt @@ -0,0 +1,16 @@ +--TEST-- +Inexistent class as type receiving scalar argument +--FILE-- +<?php + +function foo(bar $ex) {} +foo(null); + +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be an instance of bar, null given, called in %s on line %d and defined in %s:%d +Stack trace: +#0 %s(%d): foo(NULL) +#1 {main} + thrown in %s on line %d + diff --git a/Zend/tests/type_declarations/internal_function_strict_mode.phpt b/Zend/tests/type_declarations/internal_function_strict_mode.phpt new file mode 100644 index 0000000..4e792fa --- /dev/null +++ b/Zend/tests/type_declarations/internal_function_strict_mode.phpt @@ -0,0 +1,35 @@ +--TEST-- +Scalar type - internal function strict mode +--FILE-- +<?php +declare(strict_types=1); + +echo "*** Trying Ord With Integer" . PHP_EOL; +try { + var_dump(ord(1)); +} catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; +} + +echo "*** Trying Array Map With Invalid Callback" . PHP_EOL; +try { + array_map([null, "bar"], []); +} catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; +} + +echo "*** Trying Strlen With Float" . PHP_EOL; +try { + var_dump(strlen(1.5)); +} catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; +} + +?> +--EXPECTF-- +*** Trying Ord With Integer +*** Caught ord() expects parameter 1 to be string, integer given +*** Trying Array Map With Invalid Callback +*** Caught array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object +*** Trying Strlen With Float +*** Caught strlen() expects parameter 1 to be string, float given diff --git a/Zend/tests/type_declarations/return_separation.phpt b/Zend/tests/type_declarations/return_separation.phpt new file mode 100644 index 0000000..7e9d095 --- /dev/null +++ b/Zend/tests/type_declarations/return_separation.phpt @@ -0,0 +1,27 @@ +--TEST-- +Return values are separated for references with rc=1 +--FILE-- +<?php + +function test1() : array { + $array = []; + $ref =& $array; + unset($ref); + return $array; +} + +function test2() : string { + $int = 42; + $ref =& $int; + unset($ref); + return $int; +} + +var_dump(test1()); +var_dump(test2()); + +?> +--EXPECT-- +array(0) { +} +string(2) "42" diff --git a/Zend/tests/type_declarations/scalar_basic.phpt b/Zend/tests/type_declarations/scalar_basic.phpt new file mode 100644 index 0000000..51c3664 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_basic.phpt @@ -0,0 +1,277 @@ +--TEST-- +Scalar type basics +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (\TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} +echo PHP_EOL . "Done"; +?> +--EXPECTF-- + +Testing 'int' type: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +int(1) + +*** Trying float(1) +int(1) + +*** Trying float(1.5) +int(1) + +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(%d) +int(%d) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +int(1) + +*** Trying bool(false) +int(0) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +float(1) + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(%d) +float(%s) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +float(1) + +*** Trying bool(false) +float(0) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying int(1) +string(1) "1" + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +string(1) "1" + +*** Trying float(1.5) +string(3) "1.5" + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(%d) +string(%d) "%d" + +*** Trying float(NAN) +string(3) "NAN" + +*** Trying bool(true) +string(1) "1" + +*** Trying bool(false) +string(0) "" + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +string(6) "foobar" + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying int(1) +bool(true) + +*** Trying string(1) "1" +bool(true) + +*** Trying float(1) +bool(true) + +*** Trying float(1.5) +bool(true) + +*** Trying string(2) "1a" +bool(true) + +*** Trying string(1) "a" +bool(true) + +*** Trying string(0) "" +bool(false) + +*** Trying int(%d) +bool(true) + +*** Trying float(NAN) +bool(true) + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#%s (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(%d) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_constant_defaults.phpt b/Zend/tests/type_declarations/scalar_constant_defaults.phpt new file mode 100644 index 0000000..2982d9b --- /dev/null +++ b/Zend/tests/type_declarations/scalar_constant_defaults.phpt @@ -0,0 +1,83 @@ +--TEST-- +Scalar type - default via constants +--FILE-- +<?php + +const INT_VAL = 10; +const FLOAT_VAL = 10.5; +const STRING_VAL = "this is a test"; +const INT_ADD_VAL = 10 + 15; +const FLOAT_ADD_VAL = 10.5 + 0.2; +const STRING_ADD_VAL = "this" . " is a test"; +const NULL_VAL = null; + +function int_val(int $a = INT_VAL): int { + return $a; +} + +function float_val(float $a = FLOAT_VAL): float { + return $a; +} + +function string_val(string $a = STRING_VAL): string { + return $a; +} + +function int_add_val(int $a = INT_ADD_VAL): int { + return $a; +} + +function float_add_val(float $a = FLOAT_ADD_VAL): float { + return $a; +} + +function string_add_val(string $a = STRING_ADD_VAL): string { + return $a; +} + +function int_val_default_null(int $a = NULL_VAL) { + return $a; +} + +echo "Testing int val" . PHP_EOL; +var_dump(int_val()); + +echo "Testing float val" . PHP_EOL; +var_dump(float_val()); + +echo "Testing string val" . PHP_EOL; +var_dump(string_val()); + +echo "Testing int add val" . PHP_EOL; +var_dump(int_add_val()); + +echo "Testing float add val" . PHP_EOL; +var_dump(float_add_val()); + +echo "Testing string add val" . PHP_EOL; +var_dump(string_add_val()); + +echo "Testing int with default null constant" . PHP_EOL; +var_dump(int_val_default_null()); + +echo "Testing int with null null constant" . PHP_EOL; +var_dump(int_val_default_null(null)); + +?> +--EXPECTF-- +Testing int val +int(10) +Testing float val +float(10.5) +Testing string val +string(14) "this is a test" +Testing int add val +int(25) +Testing float add val +float(10.7) +Testing string add val +string(14) "this is a test" +Testing int with default null constant +NULL +Testing int with null null constant +NULL diff --git a/Zend/tests/type_declarations/scalar_constant_defaults_error.phpt b/Zend/tests/type_declarations/scalar_constant_defaults_error.phpt new file mode 100644 index 0000000..dcbb3e8 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_constant_defaults_error.phpt @@ -0,0 +1,20 @@ +--TEST-- +Scalar type - default via constants - error condition +--FILE-- +<?php + +const STRING_VAL = "test"; + +function int_val(int $a = STRING_VAL): int { + return $a; +} + +var_dump(int_val()); + +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to int_val() must be of the type integer, string given, called in %s on line %d and defined in %s:%d +Stack trace: +#0 %s(%d): int_val() +#1 {main} + thrown in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt b/Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt new file mode 100644 index 0000000..5e85eba --- /dev/null +++ b/Zend/tests/type_declarations/scalar_float_with_integer_default_strict.phpt @@ -0,0 +1,17 @@ +--TEST-- +Float type should allow an integer as default even with strict types +--FILE-- +<?php + +declare(strict_types=1); + +function test(float $arg = 0) +{ + var_dump($arg); +} + +test(); + +?> +--EXPECT-- +float(0) diff --git a/Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt b/Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt new file mode 100644 index 0000000..0289e13 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_float_with_integer_default_weak.phpt @@ -0,0 +1,15 @@ +--TEST-- +Float type should allow an integer as default +--FILE-- +<?php + +function test(float $arg = 0) +{ + var_dump($arg); +} + +test(); + +?> +--EXPECT-- +float(0) diff --git a/Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt b/Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt new file mode 100644 index 0000000..7bc2fda --- /dev/null +++ b/Zend/tests/type_declarations/scalar_float_with_invalid_default.phpt @@ -0,0 +1,16 @@ +--TEST-- +Float type should not allow invalid types as default +--FILE-- +<?php + +function test(float $arg = true) +{ + var_dump($arg); +} + +test(); + +?> +--EXPECTF-- + +Fatal error: Default value for parameters with a float type can only be float, integer, or NULL in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_none.phpt b/Zend/tests/type_declarations/scalar_none.phpt new file mode 100644 index 0000000..3bec609 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_none.phpt @@ -0,0 +1,54 @@ +--TEST-- +Scalar type missing parameters +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; }, + 'int nullable' => function (int $i = NULL) { return $i; }, + 'float nullable' => function (float $f = NULL) { return $f; }, + 'string nullable' => function (string $s = NULL) { return $s; }, + 'bool nullable' => function (bool $b = NULL) { return $b; } +]; + +foreach ($functions as $type => $function) { + echo "Testing $type:", PHP_EOL; + try { + var_dump($function()); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } +} +echo PHP_EOL . "Done"; +--EXPECTF-- +Testing int: +*** Caught Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d +Testing float: +*** Caught Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d +Testing string: +*** Caught Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d +Testing bool: +*** Caught Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d +Testing int nullable: +NULL +Testing float nullable: +NULL +Testing string nullable: +NULL +Testing bool nullable: +NULL + +Done diff --git a/Zend/tests/type_declarations/scalar_null.phpt b/Zend/tests/type_declarations/scalar_null.phpt new file mode 100644 index 0000000..6b9930f --- /dev/null +++ b/Zend/tests/type_declarations/scalar_null.phpt @@ -0,0 +1,56 @@ +--TEST-- +Scalar type nullability +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; }, + 'int nullable' => function (int $i = NULL) { return $i; }, + 'float nullable' => function (float $f = NULL) { return $f; }, + 'string nullable' => function (string $s = NULL) { return $s; }, + 'bool nullable' => function (bool $b = NULL) { return $b; } +]; + +foreach ($functions as $type => $function) { + echo "Testing $type:", PHP_EOL; + try { + var_dump($function(null)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing int: +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d +Testing float: +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d +Testing string: +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d +Testing bool: +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d +Testing int nullable: +NULL +Testing float nullable: +NULL +Testing string nullable: +NULL +Testing bool nullable: +NULL + +Done diff --git a/Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt b/Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt new file mode 100644 index 0000000..b093983 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_relative_typehint_disallowed.phpt @@ -0,0 +1,14 @@ +--TEST-- +Scalar type - disallow relative types +--FILE-- +<?php + +function foo(bar\int $a): int { + return $a; +} + +foo(10); + +?> +--EXPECTF-- +Fatal error: Cannot use 'bar\int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved2.phpt b/Zend/tests/type_declarations/scalar_reserved2.phpt new file mode 100644 index 0000000..893f4b5 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved2.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (2) +--FILE-- +<?php + +class int {} +--EXPECTF-- +Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt new file mode 100644 index 0000000..777cf9c --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved2_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (2) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "int"); +--EXPECTF-- +Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved2_use.phpt b/Zend/tests/type_declarations/scalar_reserved2_use.phpt new file mode 100644 index 0000000..3e8d1be --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved2_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (2) - use +--FILE-- +<?php + +use foobar as int; +--EXPECTF-- +Fatal error: Cannot use foobar as int because 'int' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved3.phpt b/Zend/tests/type_declarations/scalar_reserved3.phpt new file mode 100644 index 0000000..433673e --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved3.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (3) +--FILE-- +<?php + +class float {} +--EXPECTF-- +Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt new file mode 100644 index 0000000..dc8f319 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved3_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (3) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "float"); +--EXPECTF-- +Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved3_use.phpt b/Zend/tests/type_declarations/scalar_reserved3_use.phpt new file mode 100644 index 0000000..af76abf --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved3_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (3) - use +--FILE-- +<?php + +use foobar as float; +--EXPECTF-- +Fatal error: Cannot use foobar as float because 'float' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved4.phpt b/Zend/tests/type_declarations/scalar_reserved4.phpt new file mode 100644 index 0000000..dd5ff89 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved4.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (4) +--FILE-- +<?php + +class string {} +--EXPECTF-- +Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt new file mode 100644 index 0000000..ebb6ac3 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved4_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (4) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "string"); +--EXPECTF-- +Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved4_use.phpt b/Zend/tests/type_declarations/scalar_reserved4_use.phpt new file mode 100644 index 0000000..e2fc0ae --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved4_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (4) - use +--FILE-- +<?php + +use foobar as string; +--EXPECTF-- +Fatal error: Cannot use foobar as string because 'string' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved6.phpt b/Zend/tests/type_declarations/scalar_reserved6.phpt new file mode 100644 index 0000000..f84ec94 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved6.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (6) +--FILE-- +<?php + +class bool {} +--EXPECTF-- +Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt b/Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt new file mode 100644 index 0000000..8a777ec --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved6_class_alias.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (6) - class_alias +--FILE-- +<?php + +class foobar {} +class_alias("foobar", "bool"); +--EXPECTF-- +Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved6_use.phpt b/Zend/tests/type_declarations/scalar_reserved6_use.phpt new file mode 100644 index 0000000..e9de61f --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved6_use.phpt @@ -0,0 +1,8 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (6) - use +--FILE-- +<?php + +use foobar as bool; +--EXPECTF-- +Fatal error: Cannot use foobar as bool because 'bool' is a special class name in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_reserved7.phpt b/Zend/tests/type_declarations/scalar_reserved7.phpt new file mode 100644 index 0000000..1e23d59 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_reserved7.phpt @@ -0,0 +1,9 @@ +--TEST-- +Scalar type names cannot be used as class, trait or interface names (7) +--FILE-- +<?php +namespace foo; + +class int {} +--EXPECTF-- +Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_return_basic.phpt b/Zend/tests/type_declarations/scalar_return_basic.phpt new file mode 100644 index 0000000..4e0650e --- /dev/null +++ b/Zend/tests/type_declarations/scalar_return_basic.phpt @@ -0,0 +1,216 @@ +--TEST-- +Return scalar type basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying int(2147483647) +int(2147483647) +*** Trying float(NAN) +*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d + +Testing 'float' type: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying int(2147483647) +float(2147483647) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d + +Testing 'string' type: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(2147483647) +string(10) "2147483647" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +string(6) "foobar" +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d + +Testing 'bool' type: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(2147483647) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt new file mode 100644 index 0000000..e8f69bc --- /dev/null +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -0,0 +1,216 @@ +--TEST-- +Return scalar type basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying int(9223372036854775807) +int(9223372036854775807) +*** Trying float(NAN) +*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d + +Testing 'float' type: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d + +Testing 'string' type: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(9223372036854775807) +string(19) "9223372036854775807" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +string(6) "foobar" +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d + +Testing 'bool' type: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(9223372036854775807) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict.phpt b/Zend/tests/type_declarations/scalar_strict.phpt new file mode 100644 index 0000000..40b036e --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict.phpt @@ -0,0 +1,279 @@ +--TEST-- +Scalar type strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> +--FILE-- +<?php +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(2147483647) +int(2147483647) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(2147483647) +float(2147483647) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(2147483647) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying int(2147483647) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict_64bit.phpt b/Zend/tests/type_declarations/scalar_strict_64bit.phpt new file mode 100644 index 0000000..3e748ed --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_64bit.phpt @@ -0,0 +1,279 @@ +--TEST-- +Scalar type strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +int(9223372036854775807) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict_basic.phpt b/Zend/tests/type_declarations/scalar_strict_basic.phpt new file mode 100644 index 0000000..3ee94a2 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_basic.phpt @@ -0,0 +1,181 @@ +--TEST-- +Strict scalar type basics +--FILE-- +<?php + +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; + +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +$values = [ + 1, + 1.0, + "1", + TRUE, + FALSE, + NULL, + [], + new StdClass, + fopen("data:text/plain,foobar", "r") +]; + +function type($value) { + if (is_float($value)) { + return "float"; + } else if (is_bool($value)) { + return $value ? "true" : "false"; + } else if (is_null($value)) { + return "null"; + } else { + return gettype($value); + } +} + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' type:", PHP_EOL; + foreach ($values as $value) { + $errored = false; + echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL; + try { + var_dump($function($value)); + } catch (TypeError $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' type: + +*** Trying integer value +int(1) + +*** Trying float value +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string value +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying true value +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying false value +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' type: + +*** Trying integer value +float(1) + +*** Trying float value +float(1) + +*** Trying string value +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying true value +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying false value +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' type: + +*** Trying integer value +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float value +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string value +string(1) "1" + +*** Trying true value +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying false value +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' type: + +*** Trying integer value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying true value +bool(true) + +*** Trying false value +bool(false) + +*** Trying null value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource value +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt new file mode 100644 index 0000000..2a2b3e6 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test strict declaration being first operation only +--FILE-- +<?php + +function takes_int(int $x) { + global $errored; + if ($errored) { + echo "Failure!", PHP_EOL; + $errored = FALSE; + } else { + echo "Success!", PHP_EOL; + } +} + +?> +<?php + +declare(strict_types=1); +var_dump(takes_int(32)); + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt new file mode 100644 index 0000000..09ac111 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_002.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test strict declaration being first operation only 002 +--FILE-- +<?php + +namespace Foo; + +declare(strict_types=1); + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt new file mode 100644 index 0000000..6ec5b59 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_003.phpt @@ -0,0 +1,11 @@ +--TEST-- +Test strict declaration being first operation only 003 +--FILE-- +hi<?php + +declare(strict_types=1); +var_dump(strlen(32)); + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt new file mode 100644 index 0000000..6000324 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_004.phpt @@ -0,0 +1,17 @@ +--TEST-- +Test strict declaration being first operation only 004 +--FILE-- +<?php +declare(strict_types=1); + +namespace Foo { + function add1(int $arg): int { + return $arg + 1; + } +} + +namespace { + var_dump(Foo\add1(123)); +} +--EXPECT-- +int(124) diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt new file mode 100644 index 0000000..8611a20 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_005.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test strict declaration being first operation only 005 +--FILE-- +<?php + +declare(strict_types=1); + +namespace Foo; + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +int(3) \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt new file mode 100644 index 0000000..2af05b6 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_006.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test strict declaration being first operation only 006 +--SKIPIF-- +<?php +if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { + die("skip Requires configure --enable-zend-multibyte option"); +} +if (!extension_loaded("mbstring")) { + die("skip Requires mbstring extension"); +} +?> +--INI-- +zend.multibyte=1 +--FILE-- +<?php +declare(encoding="UTF-8"); +declare(strict_types=1); + +namespace Foo; + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +int(3) \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt new file mode 100644 index 0000000..3e4c693 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_007.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test strict declaration being first operation only 007 +--SKIPIF-- +<?php +if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { + die("skip Requires configure --enable-zend-multibyte option"); +} +if (!extension_loaded("mbstring")) { + die("skip Requires mbstring extension"); +} +?> +--INI-- +zend.multibyte=1 +--FILE-- +<?php +declare(strict_types=1); +declare(encoding="ISO-8859-1"); + +namespace Foo; + +var_dump(strlen("abc")); + +?> +--EXPECTF-- +int(3) \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt b/Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt new file mode 100644 index 0000000..87a09af --- /dev/null +++ b/Zend/tests/type_declarations/scalar_strict_declaration_placement_008.phpt @@ -0,0 +1,11 @@ +--TEST-- +Test strict declaration block declaration 008 +--FILE-- +<?php +declare(strict_types=1) { + var_dump(strlen("abc")); +} + +?> +--EXPECTF-- +Fatal error: strict_types declaration must not use block mode in %s on line %d \ No newline at end of file diff --git a/Zend/tests/type_declarations/scalar_weak_reference.phpt b/Zend/tests/type_declarations/scalar_weak_reference.phpt new file mode 100644 index 0000000..7406968 --- /dev/null +++ b/Zend/tests/type_declarations/scalar_weak_reference.phpt @@ -0,0 +1,29 @@ +--TEST-- +Weak scalar types, with references +--FILE-- +<?php + +// implicitly weak mode code + +function to_int(int &$x) {} +function to_float(float &$x) {} +function to_string(string &$x) {} +function to_bool(bool &$x) {} + +$x = 1.0; +var_dump($x); +to_int($x); // because $x is by-reference, the weak type converts it +var_dump($x); +to_float($x); +var_dump($x); +to_string($x); +var_dump($x); +to_bool($x); +var_dump($x); +?> +--EXPECT-- +float(1) +int(1) +float(1) +string(1) "1" +bool(true) diff --git a/Zend/tests/type_declarations/self_on_closure_in_method.phpt b/Zend/tests/type_declarations/self_on_closure_in_method.phpt new file mode 100644 index 0000000..2d5bd82 --- /dev/null +++ b/Zend/tests/type_declarations/self_on_closure_in_method.phpt @@ -0,0 +1,19 @@ +--TEST-- +self return type on closure in a method +--FILE-- +<?php + +class A { + public function test() { + return function() : self { + return $this; + }; + } +} + +var_dump((new A)->test()()); + +?> +--EXPECT-- +object(A)#1 (0) { +} diff --git a/Zend/tests/type_declarations/strict_call_weak.phpt b/Zend/tests/type_declarations/strict_call_weak.phpt new file mode 100644 index 0000000..e3a606e --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak.phpt @@ -0,0 +1,21 @@ +--TEST-- +strict_types=1 code calling strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's implicitly weak +require 'strict_call_weak_2.inc'; + +// Will succeed: Function was declared in weak mode, but that does not matter +// This file uses strict mode, so the call is strict, and float denied for int +function_declared_in_weak_mode(1.0); +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak.php on line 10 and defined in %sstrict_call_weak_2.inc:5 +Stack trace: +#0 %s(%d): function_declared_in_weak_mode(1) +#1 {main} + thrown in %sstrict_call_weak_2.inc on line 5 + diff --git a/Zend/tests/type_declarations/strict_call_weak_2.inc b/Zend/tests/type_declarations/strict_call_weak_2.inc new file mode 100644 index 0000000..cba5512 --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak_2.inc @@ -0,0 +1,7 @@ +<?php + +// implicitly weak code + +function function_declared_in_weak_mode(int $x) { + echo "Success!"; +} diff --git a/Zend/tests/type_declarations/strict_call_weak_explicit.phpt b/Zend/tests/type_declarations/strict_call_weak_explicit.phpt new file mode 100644 index 0000000..22c5b43 --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak_explicit.phpt @@ -0,0 +1,21 @@ +--TEST-- +strict_types=1 code calling explicitly strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's explicitly weak +require 'strict_call_weak_explicit_2.inc'; + +// Will succeed: Function was declared in weak mode, but that does not matter +// This file uses strict mode, so the call is strict, and float denied for int +function_declared_in_weak_mode(1.0); +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak_explicit.php on line 10 and defined in %sstrict_call_weak_explicit_2.inc:5 +Stack trace: +#0 %s(%d): function_declared_in_weak_mode(1) +#1 {main} + thrown in %sstrict_call_weak_explicit_2.inc on line 5 + diff --git a/Zend/tests/type_declarations/strict_call_weak_explicit_2.inc b/Zend/tests/type_declarations/strict_call_weak_explicit_2.inc new file mode 100644 index 0000000..d26c847 --- /dev/null +++ b/Zend/tests/type_declarations/strict_call_weak_explicit_2.inc @@ -0,0 +1,7 @@ +<?php + +declare(strict_types=0); + +function function_declared_in_weak_mode(int $x) { + echo "Success!"; +} diff --git a/Zend/tests/type_declarations/strict_include_explicit_weak.phpt b/Zend/tests/type_declarations/strict_include_explicit_weak.phpt new file mode 100644 index 0000000..a42d633 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_explicit_weak.phpt @@ -0,0 +1,14 @@ +--TEST-- +strict_types=1 code including explicitly strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's explicitly weak +require 'strict_include_explicit_weak_2.inc'; + +// calls within that file should stay weak, despite being included by strict fille +?> +--EXPECTF-- +Success! diff --git a/Zend/tests/type_declarations/strict_include_explicit_weak_2.inc b/Zend/tests/type_declarations/strict_include_explicit_weak_2.inc new file mode 100644 index 0000000..3da32e1 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_explicit_weak_2.inc @@ -0,0 +1,9 @@ +<?php + +declare(strict_types=0); + +function takes_int(int $x) { + echo "Success!"; +} + +takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/type_declarations/strict_include_weak.phpt b/Zend/tests/type_declarations/strict_include_weak.phpt new file mode 100644 index 0000000..ce29db7 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_weak.phpt @@ -0,0 +1,14 @@ +--TEST-- +strict_types=1 code including strict_types=0 code +--FILE-- +<?php + +declare(strict_types=1); + +// file that's implicitly weak +require 'strict_include_weak_2.inc'; + +// calls within that file should stay weak, despite being included by strict file +?> +--EXPECTF-- +Success! diff --git a/Zend/tests/type_declarations/strict_include_weak_2.inc b/Zend/tests/type_declarations/strict_include_weak_2.inc new file mode 100644 index 0000000..d4ee8a8 --- /dev/null +++ b/Zend/tests/type_declarations/strict_include_weak_2.inc @@ -0,0 +1,9 @@ +<?php + +// implicitly weak code + +function takes_int(int $x) { + echo "Success!"; +} + +takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/type_declarations/strict_nested.phpt b/Zend/tests/type_declarations/strict_nested.phpt new file mode 100644 index 0000000..2001f8b --- /dev/null +++ b/Zend/tests/type_declarations/strict_nested.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test nested function calls in strict_types=0 and strict_types=1 modes +--FILE-- +<?php + +function takes_int(int $x) { + global $errored; + if ($errored) { + echo "Failure!", PHP_EOL; + $errored = FALSE; + } else { + echo "Success!", PHP_EOL; + } +} + +declare(strict_types=1) { + function strict_calls_takes_int() { + takes_int(1.0); // should fail, strict mode + } + + class StrictTakesIntCaller { + public function call() { + takes_int(1.0); // should fail, strict mode + } + } +} + +declare(strict_types=0) { + function explicit_weak_calls_takes_int() { + takes_int(1.0); // should succeed, weak mode + } + + class ExplicitWeakTakesIntCaller { + public function call() { + takes_int(1.0); // should succeed, weak mode + } + } +} + + +?> +--EXPECTF-- +Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/type_declarations/weak_call_strict.phpt b/Zend/tests/type_declarations/weak_call_strict.phpt new file mode 100644 index 0000000..b0ea78c --- /dev/null +++ b/Zend/tests/type_declarations/weak_call_strict.phpt @@ -0,0 +1,16 @@ +--TEST-- +strict_types=0 code calling strict_types=1 code +--FILE-- +<?php + +// implicitly strict_types=0 + +// file with strict_types=1 +require 'weak_call_strict_2.inc'; + +// Will succeed: Function was declared in strict mode, but that does not matter +// This file uses weak mode, so the call is weak, and float accepted for int +function_declared_in_strict_mode(1.0); +?> +--EXPECT-- +Success! diff --git a/Zend/tests/type_declarations/weak_call_strict_2.inc b/Zend/tests/type_declarations/weak_call_strict_2.inc new file mode 100644 index 0000000..fe2a17f --- /dev/null +++ b/Zend/tests/type_declarations/weak_call_strict_2.inc @@ -0,0 +1,7 @@ +<?php + +declare(strict_types=1); + +function function_declared_in_strict_mode(int $x) { + echo "Success!"; +} diff --git a/Zend/tests/type_declarations/weak_explicit_call_strict.phpt b/Zend/tests/type_declarations/weak_explicit_call_strict.phpt new file mode 100644 index 0000000..b07cef5 --- /dev/null +++ b/Zend/tests/type_declarations/weak_explicit_call_strict.phpt @@ -0,0 +1,16 @@ +--TEST-- +Explicitly strict_types=0 code calling strict_types=1 code +--FILE-- +<?php + +declare(strict_types=0); + +// file with strict_types=1 +require 'weak_call_strict_2.inc'; + +// Will succeed: Function was declared in strict mode, but that does not matter +// This file uses weak mode, so the call is weak, and float accepted for int +function_declared_in_strict_mode(1.0); +?> +--EXPECT-- +Success! diff --git a/Zend/tests/type_declarations/weak_include_strict.phpt b/Zend/tests/type_declarations/weak_include_strict.phpt new file mode 100644 index 0000000..e49485d --- /dev/null +++ b/Zend/tests/type_declarations/weak_include_strict.phpt @@ -0,0 +1,19 @@ +--TEST-- +strict_types=0 code including strict_types=1 code +--FILE-- +<?php + +// implicitly weak code + +// file with strict_types=1 +require 'weak_include_strict_2.inc'; + +// calls within that file should stay strict, despite being included by weak file +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 +Stack trace: +#0 %s(%d): takes_int(1) +#1 %s(%d): require('%s') +#2 {main} + thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/type_declarations/weak_include_strict_2.inc b/Zend/tests/type_declarations/weak_include_strict_2.inc new file mode 100644 index 0000000..8acfc03 --- /dev/null +++ b/Zend/tests/type_declarations/weak_include_strict_2.inc @@ -0,0 +1,9 @@ +<?php + +declare(strict_types=1); + +function takes_int(int $x) { + echo "Success!"; +} + +takes_int(1.0); // fails in strict mode diff --git a/Zend/tests/typehints/add_return_type.phpt b/Zend/tests/typehints/add_return_type.phpt deleted file mode 100644 index de8a17d..0000000 --- a/Zend/tests/typehints/add_return_type.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Adding a return type during inheritance is allowed ---FILE-- -<?php - -interface One { - public function a(); - public function b(); - public function c(); - public function d(); -} - -interface Two extends One { - public function a() : stdClass; - public function c() : callable; - public function b() : array; - public function d() : int; -} - -?> -Done ---EXPECT-- -Done diff --git a/Zend/tests/typehints/default_boolean_hint_values.phpt b/Zend/tests/typehints/default_boolean_hint_values.phpt deleted file mode 100644 index 6ba2628..0000000 --- a/Zend/tests/typehints/default_boolean_hint_values.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Default values for boolean hints should work ---FILE-- -<?php - -function foo(bool $x = true, bool $y = false) { - var_dump($x, $y); -} - - - -foo(); -?> ---EXPECTF-- -bool(true) -bool(false) diff --git a/Zend/tests/typehints/explicit_weak_include_strict.phpt b/Zend/tests/typehints/explicit_weak_include_strict.phpt deleted file mode 100644 index fb53d8c..0000000 --- a/Zend/tests/typehints/explicit_weak_include_strict.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -explicitly strict_types=0 code including strict_types=1 code ---FILE-- -<?php - -declare(strict_types=0); - -// file with strict_types=1 -require 'weak_include_strict_2.inc'; - -// calls within that file should stay strict, despite being included by weak file -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 -Stack trace: -#0 %s(%d): takes_int(1) -#1 %s(%d): require('%s') -#2 {main} - thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt b/Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt deleted file mode 100644 index 3bacf82..0000000 --- a/Zend/tests/typehints/inexistent_class_hint_with_scalar_arg.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Inexistent class as typehint receiving scalar argument ---FILE-- -<?php - -function foo(bar $ex) {} -foo(null); - -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be an instance of bar, null given, called in %s on line %d and defined in %s:%d -Stack trace: -#0 %s(%d): foo(NULL) -#1 {main} - thrown in %s on line %d - diff --git a/Zend/tests/typehints/internal_function_strict_mode.phpt b/Zend/tests/typehints/internal_function_strict_mode.phpt deleted file mode 100644 index f501c2b..0000000 --- a/Zend/tests/typehints/internal_function_strict_mode.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -Scalar type hint - internal function strict mode ---FILE-- -<?php -declare(strict_types=1); - -echo "*** Trying Ord With Integer" . PHP_EOL; -try { - var_dump(ord(1)); -} catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; -} - -echo "*** Trying Array Map With Invalid Callback" . PHP_EOL; -try { - array_map([null, "bar"], []); -} catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; -} - -echo "*** Trying Strlen With Float" . PHP_EOL; -try { - var_dump(strlen(1.5)); -} catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; -} - -?> ---EXPECTF-- -*** Trying Ord With Integer -*** Caught ord() expects parameter 1 to be string, integer given -*** Trying Array Map With Invalid Callback -*** Caught array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object -*** Trying Strlen With Float -*** Caught strlen() expects parameter 1 to be string, float given \ No newline at end of file diff --git a/Zend/tests/typehints/return_separation.phpt b/Zend/tests/typehints/return_separation.phpt deleted file mode 100644 index 7e9d095..0000000 --- a/Zend/tests/typehints/return_separation.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Return values are separated for references with rc=1 ---FILE-- -<?php - -function test1() : array { - $array = []; - $ref =& $array; - unset($ref); - return $array; -} - -function test2() : string { - $int = 42; - $ref =& $int; - unset($ref); - return $int; -} - -var_dump(test1()); -var_dump(test2()); - -?> ---EXPECT-- -array(0) { -} -string(2) "42" diff --git a/Zend/tests/typehints/scalar_basic.phpt b/Zend/tests/typehints/scalar_basic.phpt deleted file mode 100644 index f27dc2b..0000000 --- a/Zend/tests/typehints/scalar_basic.phpt +++ /dev/null @@ -1,277 +0,0 @@ ---TEST-- -Scalar type hint basics ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo PHP_EOL . "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (\TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} -echo PHP_EOL . "Done"; -?> ---EXPECTF-- - -Testing 'int' typehint: - -*** Trying int(1) -int(1) - -*** Trying string(1) "1" -int(1) - -*** Trying float(1) -int(1) - -*** Trying float(1.5) -int(1) - -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -int(1) - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying int(%d) -int(%d) - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying bool(true) -int(1) - -*** Trying bool(false) -int(0) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying int(1) -float(1) - -*** Trying string(1) "1" -float(1) - -*** Trying float(1) -float(1) - -*** Trying float(1.5) -float(1.5) - -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -float(1) - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying int(%d) -float(%s) - -*** Trying float(NAN) -float(NAN) - -*** Trying bool(true) -float(1) - -*** Trying bool(false) -float(0) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying int(1) -string(1) "1" - -*** Trying string(1) "1" -string(1) "1" - -*** Trying float(1) -string(1) "1" - -*** Trying float(1.5) -string(3) "1.5" - -*** Trying string(2) "1a" -string(2) "1a" - -*** Trying string(1) "a" -string(1) "a" - -*** Trying string(0) "" -string(0) "" - -*** Trying int(%d) -string(%d) "%d" - -*** Trying float(NAN) -string(3) "NAN" - -*** Trying bool(true) -string(1) "1" - -*** Trying bool(false) -string(0) "" - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -string(6) "foobar" - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying int(1) -bool(true) - -*** Trying string(1) "1" -bool(true) - -*** Trying float(1) -bool(true) - -*** Trying float(1.5) -bool(true) - -*** Trying string(2) "1a" -bool(true) - -*** Trying string(1) "a" -bool(true) - -*** Trying string(0) "" -bool(false) - -*** Trying int(%d) -bool(true) - -*** Trying float(NAN) -bool(true) - -*** Trying bool(true) -bool(true) - -*** Trying bool(false) -bool(false) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object(stdClass)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying object(Stringable)#%s (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource(%d) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_constant_defaults.phpt b/Zend/tests/typehints/scalar_constant_defaults.phpt deleted file mode 100644 index 4441022..0000000 --- a/Zend/tests/typehints/scalar_constant_defaults.phpt +++ /dev/null @@ -1,83 +0,0 @@ ---TEST-- -Scalar type hint - default via constants ---FILE-- -<?php - -const INT_VAL = 10; -const FLOAT_VAL = 10.5; -const STRING_VAL = "this is a test"; -const INT_ADD_VAL = 10 + 15; -const FLOAT_ADD_VAL = 10.5 + 0.2; -const STRING_ADD_VAL = "this" . " is a test"; -const NULL_VAL = null; - -function int_val(int $a = INT_VAL): int { - return $a; -} - -function float_val(float $a = FLOAT_VAL): float { - return $a; -} - -function string_val(string $a = STRING_VAL): string { - return $a; -} - -function int_add_val(int $a = INT_ADD_VAL): int { - return $a; -} - -function float_add_val(float $a = FLOAT_ADD_VAL): float { - return $a; -} - -function string_add_val(string $a = STRING_ADD_VAL): string { - return $a; -} - -function int_val_default_null(int $a = NULL_VAL) { - return $a; -} - -echo "Testing int val" . PHP_EOL; -var_dump(int_val()); - -echo "Testing float val" . PHP_EOL; -var_dump(float_val()); - -echo "Testing string val" . PHP_EOL; -var_dump(string_val()); - -echo "Testing int add val" . PHP_EOL; -var_dump(int_add_val()); - -echo "Testing float add val" . PHP_EOL; -var_dump(float_add_val()); - -echo "Testing string add val" . PHP_EOL; -var_dump(string_add_val()); - -echo "Testing int with default null constant" . PHP_EOL; -var_dump(int_val_default_null()); - -echo "Testing int with null null constant" . PHP_EOL; -var_dump(int_val_default_null(null)); - -?> ---EXPECTF-- -Testing int val -int(10) -Testing float val -float(10.5) -Testing string val -string(14) "this is a test" -Testing int add val -int(25) -Testing float add val -float(10.7) -Testing string add val -string(14) "this is a test" -Testing int with default null constant -NULL -Testing int with null null constant -NULL \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_constant_defaults_error.phpt b/Zend/tests/typehints/scalar_constant_defaults_error.phpt deleted file mode 100644 index f341d20..0000000 --- a/Zend/tests/typehints/scalar_constant_defaults_error.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Scalar type hint - default via constants - error condition ---FILE-- -<?php - -const STRING_VAL = "test"; - -function int_val(int $a = STRING_VAL): int { - return $a; -} - -var_dump(int_val()); - -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to int_val() must be of the type integer, string given, called in %s on line %d and defined in %s:%d -Stack trace: -#0 %s(%d): int_val() -#1 {main} - thrown in %s on line %d \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt b/Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt deleted file mode 100644 index b1aab43..0000000 --- a/Zend/tests/typehints/scalar_float_with_integer_default_strict.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Float type hint should allow an integer as default even with strict types ---FILE-- -<?php - -declare(strict_types=1); - -function test(float $arg = 0) -{ - var_dump($arg); -} - -test(); - -?> ---EXPECT-- -float(0) diff --git a/Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt b/Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt deleted file mode 100644 index ab32066..0000000 --- a/Zend/tests/typehints/scalar_float_with_integer_default_weak.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Float type hint should allow an integer as default ---FILE-- -<?php - -function test(float $arg = 0) -{ - var_dump($arg); -} - -test(); - -?> ---EXPECT-- -float(0) diff --git a/Zend/tests/typehints/scalar_float_with_invalid_default.phpt b/Zend/tests/typehints/scalar_float_with_invalid_default.phpt deleted file mode 100644 index 6b67985..0000000 --- a/Zend/tests/typehints/scalar_float_with_invalid_default.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Float type hint should not allow invalid types as default ---FILE-- -<?php - -function test(float $arg = true) -{ - var_dump($arg); -} - -test(); - -?> ---EXPECTF-- - -Fatal error: Default value for parameters with a float type hint can only be float, integer, or NULL in %s on line %d diff --git a/Zend/tests/typehints/scalar_none.phpt b/Zend/tests/typehints/scalar_none.phpt deleted file mode 100644 index 5a98377..0000000 --- a/Zend/tests/typehints/scalar_none.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Scalar type hint missing parameters ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; }, - 'int nullable' => function (int $i = NULL) { return $i; }, - 'float nullable' => function (float $f = NULL) { return $f; }, - 'string nullable' => function (string $s = NULL) { return $s; }, - 'bool nullable' => function (bool $b = NULL) { return $b; } -]; - -foreach ($functions as $type => $function) { - echo "Testing $type:", PHP_EOL; - try { - var_dump($function()); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } -} -echo PHP_EOL . "Done"; ---EXPECTF-- -Testing int: -*** Caught Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d -Testing float: -*** Caught Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d -Testing string: -*** Caught Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d -Testing bool: -*** Caught Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d -Testing int nullable: -NULL -Testing float nullable: -NULL -Testing string nullable: -NULL -Testing bool nullable: -NULL - -Done diff --git a/Zend/tests/typehints/scalar_null.phpt b/Zend/tests/typehints/scalar_null.phpt deleted file mode 100644 index f409e34..0000000 --- a/Zend/tests/typehints/scalar_null.phpt +++ /dev/null @@ -1,56 +0,0 @@ ---TEST-- -Scalar type hint nullability ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; }, - 'int nullable' => function (int $i = NULL) { return $i; }, - 'float nullable' => function (float $f = NULL) { return $f; }, - 'string nullable' => function (string $s = NULL) { return $s; }, - 'bool nullable' => function (bool $b = NULL) { return $b; } -]; - -foreach ($functions as $type => $function) { - echo "Testing $type:", PHP_EOL; - try { - var_dump($function(null)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing int: -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d -Testing float: -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d -Testing string: -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d -Testing bool: -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d -Testing int nullable: -NULL -Testing float nullable: -NULL -Testing string nullable: -NULL -Testing bool nullable: -NULL - -Done diff --git a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt b/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt deleted file mode 100644 index d850912..0000000 --- a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Scalar type hint - disallow relative typehints ---FILE-- -<?php - -function foo(bar\int $a): int { - return $a; -} - -foo(10); - -?> ---EXPECTF-- -Fatal error: Cannot use 'bar\int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved2.phpt b/Zend/tests/typehints/scalar_reserved2.phpt deleted file mode 100644 index 01f36fd..0000000 --- a/Zend/tests/typehints/scalar_reserved2.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (2) ---FILE-- -<?php - -class int {} ---EXPECTF-- -Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved2_class_alias.phpt b/Zend/tests/typehints/scalar_reserved2_class_alias.phpt deleted file mode 100644 index 02d6bb4..0000000 --- a/Zend/tests/typehints/scalar_reserved2_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (2) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "int"); ---EXPECTF-- -Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved2_use.phpt b/Zend/tests/typehints/scalar_reserved2_use.phpt deleted file mode 100644 index e61db5c..0000000 --- a/Zend/tests/typehints/scalar_reserved2_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (2) - use ---FILE-- -<?php - -use foobar as int; ---EXPECTF-- -Fatal error: Cannot use foobar as int because 'int' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved3.phpt b/Zend/tests/typehints/scalar_reserved3.phpt deleted file mode 100644 index 425365b..0000000 --- a/Zend/tests/typehints/scalar_reserved3.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (3) ---FILE-- -<?php - -class float {} ---EXPECTF-- -Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved3_class_alias.phpt b/Zend/tests/typehints/scalar_reserved3_class_alias.phpt deleted file mode 100644 index 39c2e2a..0000000 --- a/Zend/tests/typehints/scalar_reserved3_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (3) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "float"); ---EXPECTF-- -Fatal error: Cannot use 'float' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved3_use.phpt b/Zend/tests/typehints/scalar_reserved3_use.phpt deleted file mode 100644 index 23be15e..0000000 --- a/Zend/tests/typehints/scalar_reserved3_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (3) - use ---FILE-- -<?php - -use foobar as float; ---EXPECTF-- -Fatal error: Cannot use foobar as float because 'float' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved4.phpt b/Zend/tests/typehints/scalar_reserved4.phpt deleted file mode 100644 index 5a190ce..0000000 --- a/Zend/tests/typehints/scalar_reserved4.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (4) ---FILE-- -<?php - -class string {} ---EXPECTF-- -Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved4_class_alias.phpt b/Zend/tests/typehints/scalar_reserved4_class_alias.phpt deleted file mode 100644 index ffaf934..0000000 --- a/Zend/tests/typehints/scalar_reserved4_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (4) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "string"); ---EXPECTF-- -Fatal error: Cannot use 'string' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved4_use.phpt b/Zend/tests/typehints/scalar_reserved4_use.phpt deleted file mode 100644 index 05a2ea1..0000000 --- a/Zend/tests/typehints/scalar_reserved4_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (4) - use ---FILE-- -<?php - -use foobar as string; ---EXPECTF-- -Fatal error: Cannot use foobar as string because 'string' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved6.phpt b/Zend/tests/typehints/scalar_reserved6.phpt deleted file mode 100644 index 1dee41f..0000000 --- a/Zend/tests/typehints/scalar_reserved6.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (6) ---FILE-- -<?php - -class bool {} ---EXPECTF-- -Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved6_class_alias.phpt b/Zend/tests/typehints/scalar_reserved6_class_alias.phpt deleted file mode 100644 index fd3c328..0000000 --- a/Zend/tests/typehints/scalar_reserved6_class_alias.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (6) - class_alias ---FILE-- -<?php - -class foobar {} -class_alias("foobar", "bool"); ---EXPECTF-- -Fatal error: Cannot use 'bool' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved6_use.phpt b/Zend/tests/typehints/scalar_reserved6_use.phpt deleted file mode 100644 index 9cb7857..0000000 --- a/Zend/tests/typehints/scalar_reserved6_use.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (6) - use ---FILE-- -<?php - -use foobar as bool; ---EXPECTF-- -Fatal error: Cannot use foobar as bool because 'bool' is a special class name in %s on line %d diff --git a/Zend/tests/typehints/scalar_reserved7.phpt b/Zend/tests/typehints/scalar_reserved7.phpt deleted file mode 100644 index d641d17..0000000 --- a/Zend/tests/typehints/scalar_reserved7.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Scalar type hint names cannot be used as class, trait or interface names (7) ---FILE-- -<?php -namespace foo; - -class int {} ---EXPECTF-- -Fatal error: Cannot use 'int' as class name as it is reserved in %s on line %d diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt deleted file mode 100644 index 9395ec9..0000000 --- a/Zend/tests/typehints/scalar_return_basic.phpt +++ /dev/null @@ -1,216 +0,0 @@ ---TEST-- -Return scalar type hint basics ---SKIPIF-- -<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function ($i): int { return $i; }, - 'float' => function ($f): float { return $f; }, - 'string' => function ($s): string { return $s; }, - 'bool' => function ($b): bool { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: -*** Trying int(1) -int(1) -*** Trying string(1) "1" -int(1) -*** Trying float(1) -int(1) -*** Trying float(1.5) -int(1) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -int(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying int(2147483647) -int(2147483647) -*** Trying float(NAN) -*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d -*** Trying bool(true) -int(1) -*** Trying bool(false) -int(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d - -Testing 'float' typehint: -*** Trying int(1) -float(1) -*** Trying string(1) "1" -float(1) -*** Trying float(1) -float(1) -*** Trying float(1.5) -float(1.5) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -float(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying int(2147483647) -float(2147483647) -*** Trying float(NAN) -float(NAN) -*** Trying bool(true) -float(1) -*** Trying bool(false) -float(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d - -Testing 'string' typehint: -*** Trying int(1) -string(1) "1" -*** Trying string(1) "1" -string(1) "1" -*** Trying float(1) -string(1) "1" -*** Trying float(1.5) -string(3) "1.5" -*** Trying string(2) "1a" -string(2) "1a" -*** Trying string(1) "a" -string(1) "a" -*** Trying string(0) "" -string(0) "" -*** Trying int(2147483647) -string(10) "2147483647" -*** Trying float(NAN) -string(3) "NAN" -*** Trying bool(true) -string(1) "1" -*** Trying bool(false) -string(0) "" -*** Trying NULL -*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -string(6) "foobar" -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d - -Testing 'bool' typehint: -*** Trying int(1) -bool(true) -*** Trying string(1) "1" -bool(true) -*** Trying float(1) -bool(true) -*** Trying float(1.5) -bool(true) -*** Trying string(2) "1a" -bool(true) -*** Trying string(1) "a" -bool(true) -*** Trying string(0) "" -bool(false) -*** Trying int(2147483647) -bool(true) -*** Trying float(NAN) -bool(true) -*** Trying bool(true) -bool(true) -*** Trying bool(false) -bool(false) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_return_basic_64bit.phpt b/Zend/tests/typehints/scalar_return_basic_64bit.phpt deleted file mode 100644 index fc7401e..0000000 --- a/Zend/tests/typehints/scalar_return_basic_64bit.phpt +++ /dev/null @@ -1,216 +0,0 @@ ---TEST-- -Return scalar type hint basics ---SKIPIF-- -<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> ---FILE-- -<?php - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function ($i): int { return $i; }, - 'float' => function ($f): float { return $f; }, - 'string' => function ($s): string { return $s; }, - 'bool' => function ($b): bool { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught ", $e->getMessage(), " in ", $e->getFile(), " on line ", $e->getLine(), PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: -*** Trying int(1) -int(1) -*** Trying string(1) "1" -int(1) -*** Trying float(1) -int(1) -*** Trying float(1.5) -int(1) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -int(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying int(9223372036854775807) -int(9223372036854775807) -*** Trying float(NAN) -*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d -*** Trying bool(true) -int(1) -*** Trying bool(false) -int(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d - -Testing 'float' typehint: -*** Trying int(1) -float(1) -*** Trying string(1) "1" -float(1) -*** Trying float(1) -float(1) -*** Trying float(1.5) -float(1.5) -*** Trying string(2) "1a" -E_NOTICE: A non well formed numeric value encountered on line %d -float(1) -*** Trying string(1) "a" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying string(0) "" -*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) -*** Trying float(NAN) -float(NAN) -*** Trying bool(true) -float(1) -*** Trying bool(false) -float(0) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d - -Testing 'string' typehint: -*** Trying int(1) -string(1) "1" -*** Trying string(1) "1" -string(1) "1" -*** Trying float(1) -string(1) "1" -*** Trying float(1.5) -string(3) "1.5" -*** Trying string(2) "1a" -string(2) "1a" -*** Trying string(1) "a" -string(1) "a" -*** Trying string(0) "" -string(0) "" -*** Trying int(9223372036854775807) -string(19) "9223372036854775807" -*** Trying float(NAN) -string(3) "NAN" -*** Trying bool(true) -string(1) "1" -*** Trying bool(false) -string(0) "" -*** Trying NULL -*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -string(6) "foobar" -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d - -Testing 'bool' typehint: -*** Trying int(1) -bool(true) -*** Trying string(1) "1" -bool(true) -*** Trying float(1) -bool(true) -*** Trying float(1.5) -bool(true) -*** Trying string(2) "1a" -bool(true) -*** Trying string(1) "a" -bool(true) -*** Trying string(0) "" -bool(false) -*** Trying int(9223372036854775807) -bool(true) -*** Trying float(NAN) -bool(true) -*** Trying bool(true) -bool(true) -*** Trying bool(false) -bool(false) -*** Trying NULL -*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d -*** Trying array(0) { -} -*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d -*** Trying object(stdClass)#6 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying object(Stringable)#7 (0) { -} -*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d -*** Trying resource(5) of type (stream) -*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict.phpt b/Zend/tests/typehints/scalar_strict.phpt deleted file mode 100644 index 59ec45a..0000000 --- a/Zend/tests/typehints/scalar_strict.phpt +++ /dev/null @@ -1,279 +0,0 @@ ---TEST-- -Scalar type hint strict mode ---SKIPIF-- -<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> ---FILE-- -<?php -declare(strict_types=1); - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo PHP_EOL . "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: - -*** Trying int(1) -int(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying int(2147483647) -int(2147483647) - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying int(1) -float(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying float(1) -float(1) - -*** Trying float(1.5) -float(1.5) - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying int(2147483647) -float(2147483647) - -*** Trying float(NAN) -float(NAN) - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying string(1) "1" -string(1) "1" - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying string(2) "1a" -string(2) "1a" - -*** Trying string(1) "a" -string(1) "a" - -*** Trying string(0) "" -string(0) "" - -*** Trying int(2147483647) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying int(2147483647) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying bool(true) -bool(true) - -*** Trying bool(false) -bool(false) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict_64bit.phpt b/Zend/tests/typehints/scalar_strict_64bit.phpt deleted file mode 100644 index 4671b07..0000000 --- a/Zend/tests/typehints/scalar_strict_64bit.phpt +++ /dev/null @@ -1,279 +0,0 @@ ---TEST-- -Scalar type hint strict mode ---SKIPIF-- -<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> ---FILE-- -<?php -declare(strict_types=1); - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -class Stringable { - public function __toString() { - return "foobar"; - } -} - -$values = [ - 1, - "1", - 1.0, - 1.5, - "1a", - "a", - "", - PHP_INT_MAX, - NAN, - TRUE, - FALSE, - NULL, - [], - new StdClass, - new Stringable, - fopen("data:text/plain,foobar", "r") -]; - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - echo PHP_EOL . "*** Trying "; - var_dump($value); - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} - -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: - -*** Trying int(1) -int(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying int(9223372036854775807) -int(9223372036854775807) - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying int(1) -float(1) - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying float(1) -float(1) - -*** Trying float(1.5) -float(1.5) - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) - -*** Trying float(NAN) -float(NAN) - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying string(1) "1" -string(1) "1" - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying string(2) "1a" -string(2) "1a" - -*** Trying string(1) "a" -string(1) "a" - -*** Trying string(0) "" -string(0) "" - -*** Trying int(9223372036854775807) -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying bool(true) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying bool(false) -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying int(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying string(1) "1" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying float(1) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying float(1.5) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying string(2) "1a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(1) "a" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying string(0) "" -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying int(9223372036854775807) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying float(NAN) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying bool(true) -bool(true) - -*** Trying bool(false) -bool(false) - -*** Trying NULL -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array(0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object(stdClass)#6 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying object(Stringable)#7 (0) { -} -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource(5) of type (stream) -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict_basic.phpt b/Zend/tests/typehints/scalar_strict_basic.phpt deleted file mode 100644 index 15030e1..0000000 --- a/Zend/tests/typehints/scalar_strict_basic.phpt +++ /dev/null @@ -1,181 +0,0 @@ ---TEST-- -Strict scalar type hint basics ---FILE-- -<?php - -declare(strict_types=1); - -$errnames = [ - E_NOTICE => 'E_NOTICE', - E_WARNING => 'E_WARNING', - E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' -]; - -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { - echo "$errnames[$errno]: $errmsg on line $line\n"; - return true; -}); - -$functions = [ - 'int' => function (int $i) { return $i; }, - 'float' => function (float $f) { return $f; }, - 'string' => function (string $s) { return $s; }, - 'bool' => function (bool $b) { return $b; } -]; - -$values = [ - 1, - 1.0, - "1", - TRUE, - FALSE, - NULL, - [], - new StdClass, - fopen("data:text/plain,foobar", "r") -]; - -function type($value) { - if (is_float($value)) { - return "float"; - } else if (is_bool($value)) { - return $value ? "true" : "false"; - } else if (is_null($value)) { - return "null"; - } else { - return gettype($value); - } -} - -foreach ($functions as $type => $function) { - echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; - foreach ($values as $value) { - $errored = false; - echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL; - try { - var_dump($function($value)); - } catch (TypeError $e) { - echo "*** Caught " . $e->getMessage() . PHP_EOL; - } - } -} -echo PHP_EOL . "Done"; -?> ---EXPECTF-- -Testing 'int' typehint: - -*** Trying integer value -int(1) - -*** Trying float value -*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d - -*** Trying string value -*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d - -*** Trying true value -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying false value -*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d - -Testing 'float' typehint: - -*** Trying integer value -float(1) - -*** Trying float value -float(1) - -*** Trying string value -*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d - -*** Trying true value -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying false value -*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d - -Testing 'string' typehint: - -*** Trying integer value -*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d - -*** Trying float value -*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d - -*** Trying string value -string(1) "1" - -*** Trying true value -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying false value -*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d - -Testing 'bool' typehint: - -*** Trying integer value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d - -*** Trying float value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d - -*** Trying string value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d - -*** Trying true value -bool(true) - -*** Trying false value -bool(false) - -*** Trying null value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d - -*** Trying array value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d - -*** Trying object value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d - -*** Trying resource value -*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d - -Done diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt deleted file mode 100644 index 2a2b3e6..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_001.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Test strict declaration being first operation only ---FILE-- -<?php - -function takes_int(int $x) { - global $errored; - if ($errored) { - echo "Failure!", PHP_EOL; - $errored = FALSE; - } else { - echo "Success!", PHP_EOL; - } -} - -?> -<?php - -declare(strict_types=1); -var_dump(takes_int(32)); - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt deleted file mode 100644 index 09ac111..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_002.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 002 ---FILE-- -<?php - -namespace Foo; - -declare(strict_types=1); - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt deleted file mode 100644 index 6ec5b59..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_003.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 003 ---FILE-- -hi<?php - -declare(strict_types=1); -var_dump(strlen(32)); - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt deleted file mode 100644 index 6000324..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_004.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 004 ---FILE-- -<?php -declare(strict_types=1); - -namespace Foo { - function add1(int $arg): int { - return $arg + 1; - } -} - -namespace { - var_dump(Foo\add1(123)); -} ---EXPECT-- -int(124) diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt deleted file mode 100644 index 8611a20..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_005.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 005 ---FILE-- -<?php - -declare(strict_types=1); - -namespace Foo; - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -int(3) \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt deleted file mode 100644 index 2af05b6..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_006.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 006 ---SKIPIF-- -<?php -if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { - die("skip Requires configure --enable-zend-multibyte option"); -} -if (!extension_loaded("mbstring")) { - die("skip Requires mbstring extension"); -} -?> ---INI-- -zend.multibyte=1 ---FILE-- -<?php -declare(encoding="UTF-8"); -declare(strict_types=1); - -namespace Foo; - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -int(3) \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt deleted file mode 100644 index 3e4c693..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_007.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Test strict declaration being first operation only 007 ---SKIPIF-- -<?php -if (!in_array("zend.detect_unicode", array_keys(ini_get_all()))) { - die("skip Requires configure --enable-zend-multibyte option"); -} -if (!extension_loaded("mbstring")) { - die("skip Requires mbstring extension"); -} -?> ---INI-- -zend.multibyte=1 ---FILE-- -<?php -declare(strict_types=1); -declare(encoding="ISO-8859-1"); - -namespace Foo; - -var_dump(strlen("abc")); - -?> ---EXPECTF-- -int(3) \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt b/Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt deleted file mode 100644 index 87a09af..0000000 --- a/Zend/tests/typehints/scalar_strict_declaration_placement_008.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Test strict declaration block declaration 008 ---FILE-- -<?php -declare(strict_types=1) { - var_dump(strlen("abc")); -} - -?> ---EXPECTF-- -Fatal error: strict_types declaration must not use block mode in %s on line %d \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_weak_reference.phpt b/Zend/tests/typehints/scalar_weak_reference.phpt deleted file mode 100644 index f397cea..0000000 --- a/Zend/tests/typehints/scalar_weak_reference.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -Weak scalar type hints, with references ---FILE-- -<?php - -// implicitly weak mode code - -function to_int(int &$x) {} -function to_float(float &$x) {} -function to_string(string &$x) {} -function to_bool(bool &$x) {} - -$x = 1.0; -var_dump($x); -to_int($x); // because $x is by-reference, the weak type hint converts it -var_dump($x); -to_float($x); -var_dump($x); -to_string($x); -var_dump($x); -to_bool($x); -var_dump($x); -?> ---EXPECT-- -float(1) -int(1) -float(1) -string(1) "1" -bool(true) diff --git a/Zend/tests/typehints/self_on_closure_in_method.phpt b/Zend/tests/typehints/self_on_closure_in_method.phpt deleted file mode 100644 index 2d5bd82..0000000 --- a/Zend/tests/typehints/self_on_closure_in_method.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -self return type on closure in a method ---FILE-- -<?php - -class A { - public function test() { - return function() : self { - return $this; - }; - } -} - -var_dump((new A)->test()()); - -?> ---EXPECT-- -object(A)#1 (0) { -} diff --git a/Zend/tests/typehints/strict_call_weak.phpt b/Zend/tests/typehints/strict_call_weak.phpt deleted file mode 100644 index e3a606e..0000000 --- a/Zend/tests/typehints/strict_call_weak.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -strict_types=1 code calling strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's implicitly weak -require 'strict_call_weak_2.inc'; - -// Will succeed: Function was declared in weak mode, but that does not matter -// This file uses strict mode, so the call is strict, and float denied for int -function_declared_in_weak_mode(1.0); -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak.php on line 10 and defined in %sstrict_call_weak_2.inc:5 -Stack trace: -#0 %s(%d): function_declared_in_weak_mode(1) -#1 {main} - thrown in %sstrict_call_weak_2.inc on line 5 - diff --git a/Zend/tests/typehints/strict_call_weak_2.inc b/Zend/tests/typehints/strict_call_weak_2.inc deleted file mode 100644 index cba5512..0000000 --- a/Zend/tests/typehints/strict_call_weak_2.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -// implicitly weak code - -function function_declared_in_weak_mode(int $x) { - echo "Success!"; -} diff --git a/Zend/tests/typehints/strict_call_weak_explicit.phpt b/Zend/tests/typehints/strict_call_weak_explicit.phpt deleted file mode 100644 index 22c5b43..0000000 --- a/Zend/tests/typehints/strict_call_weak_explicit.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -strict_types=1 code calling explicitly strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's explicitly weak -require 'strict_call_weak_explicit_2.inc'; - -// Will succeed: Function was declared in weak mode, but that does not matter -// This file uses strict mode, so the call is strict, and float denied for int -function_declared_in_weak_mode(1.0); -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak_explicit.php on line 10 and defined in %sstrict_call_weak_explicit_2.inc:5 -Stack trace: -#0 %s(%d): function_declared_in_weak_mode(1) -#1 {main} - thrown in %sstrict_call_weak_explicit_2.inc on line 5 - diff --git a/Zend/tests/typehints/strict_call_weak_explicit_2.inc b/Zend/tests/typehints/strict_call_weak_explicit_2.inc deleted file mode 100644 index d26c847..0000000 --- a/Zend/tests/typehints/strict_call_weak_explicit_2.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -declare(strict_types=0); - -function function_declared_in_weak_mode(int $x) { - echo "Success!"; -} diff --git a/Zend/tests/typehints/strict_include_explicit_weak.phpt b/Zend/tests/typehints/strict_include_explicit_weak.phpt deleted file mode 100644 index a42d633..0000000 --- a/Zend/tests/typehints/strict_include_explicit_weak.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -strict_types=1 code including explicitly strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's explicitly weak -require 'strict_include_explicit_weak_2.inc'; - -// calls within that file should stay weak, despite being included by strict fille -?> ---EXPECTF-- -Success! diff --git a/Zend/tests/typehints/strict_include_explicit_weak_2.inc b/Zend/tests/typehints/strict_include_explicit_weak_2.inc deleted file mode 100644 index 3da32e1..0000000 --- a/Zend/tests/typehints/strict_include_explicit_weak_2.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -declare(strict_types=0); - -function takes_int(int $x) { - echo "Success!"; -} - -takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/typehints/strict_include_weak.phpt b/Zend/tests/typehints/strict_include_weak.phpt deleted file mode 100644 index ce29db7..0000000 --- a/Zend/tests/typehints/strict_include_weak.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -strict_types=1 code including strict_types=0 code ---FILE-- -<?php - -declare(strict_types=1); - -// file that's implicitly weak -require 'strict_include_weak_2.inc'; - -// calls within that file should stay weak, despite being included by strict file -?> ---EXPECTF-- -Success! diff --git a/Zend/tests/typehints/strict_include_weak_2.inc b/Zend/tests/typehints/strict_include_weak_2.inc deleted file mode 100644 index d4ee8a8..0000000 --- a/Zend/tests/typehints/strict_include_weak_2.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -// implicitly weak code - -function takes_int(int $x) { - echo "Success!"; -} - -takes_int(1.0); // succeeds in weak mode diff --git a/Zend/tests/typehints/strict_nested.phpt b/Zend/tests/typehints/strict_nested.phpt deleted file mode 100644 index 2001f8b..0000000 --- a/Zend/tests/typehints/strict_nested.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -Test nested function calls in strict_types=0 and strict_types=1 modes ---FILE-- -<?php - -function takes_int(int $x) { - global $errored; - if ($errored) { - echo "Failure!", PHP_EOL; - $errored = FALSE; - } else { - echo "Success!", PHP_EOL; - } -} - -declare(strict_types=1) { - function strict_calls_takes_int() { - takes_int(1.0); // should fail, strict mode - } - - class StrictTakesIntCaller { - public function call() { - takes_int(1.0); // should fail, strict mode - } - } -} - -declare(strict_types=0) { - function explicit_weak_calls_takes_int() { - takes_int(1.0); // should succeed, weak mode - } - - class ExplicitWeakTakesIntCaller { - public function call() { - takes_int(1.0); // should succeed, weak mode - } - } -} - - -?> ---EXPECTF-- -Fatal error: strict_types declaration must be the very first statement in the script in %s on line %d diff --git a/Zend/tests/typehints/weak_call_strict.phpt b/Zend/tests/typehints/weak_call_strict.phpt deleted file mode 100644 index b0ea78c..0000000 --- a/Zend/tests/typehints/weak_call_strict.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -strict_types=0 code calling strict_types=1 code ---FILE-- -<?php - -// implicitly strict_types=0 - -// file with strict_types=1 -require 'weak_call_strict_2.inc'; - -// Will succeed: Function was declared in strict mode, but that does not matter -// This file uses weak mode, so the call is weak, and float accepted for int -function_declared_in_strict_mode(1.0); -?> ---EXPECT-- -Success! diff --git a/Zend/tests/typehints/weak_call_strict_2.inc b/Zend/tests/typehints/weak_call_strict_2.inc deleted file mode 100644 index fe2a17f..0000000 --- a/Zend/tests/typehints/weak_call_strict_2.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -declare(strict_types=1); - -function function_declared_in_strict_mode(int $x) { - echo "Success!"; -} diff --git a/Zend/tests/typehints/weak_explicit_call_strict.phpt b/Zend/tests/typehints/weak_explicit_call_strict.phpt deleted file mode 100644 index b07cef5..0000000 --- a/Zend/tests/typehints/weak_explicit_call_strict.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Explicitly strict_types=0 code calling strict_types=1 code ---FILE-- -<?php - -declare(strict_types=0); - -// file with strict_types=1 -require 'weak_call_strict_2.inc'; - -// Will succeed: Function was declared in strict mode, but that does not matter -// This file uses weak mode, so the call is weak, and float accepted for int -function_declared_in_strict_mode(1.0); -?> ---EXPECT-- -Success! diff --git a/Zend/tests/typehints/weak_include_strict.phpt b/Zend/tests/typehints/weak_include_strict.phpt deleted file mode 100644 index e49485d..0000000 --- a/Zend/tests/typehints/weak_include_strict.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -strict_types=0 code including strict_types=1 code ---FILE-- -<?php - -// implicitly weak code - -// file with strict_types=1 -require 'weak_include_strict_2.inc'; - -// calls within that file should stay strict, despite being included by weak file -?> ---EXPECTF-- -Fatal error: Uncaught TypeError: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sweak_include_strict_2.inc on line 9 and defined in %sweak_include_strict_2.inc:5 -Stack trace: -#0 %s(%d): takes_int(1) -#1 %s(%d): require('%s') -#2 {main} - thrown in %sweak_include_strict_2.inc on line 5 diff --git a/Zend/tests/typehints/weak_include_strict_2.inc b/Zend/tests/typehints/weak_include_strict_2.inc deleted file mode 100644 index 8acfc03..0000000 --- a/Zend/tests/typehints/weak_include_strict_2.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -declare(strict_types=1); - -function takes_int(int $x) { - echo "Success!"; -} - -takes_int(1.0); // fails in strict mode diff --git a/Zend/tests/variadic/typehint_error.phpt b/Zend/tests/variadic/typehint_error.phpt index 26842bb..153161a 100644 --- a/Zend/tests/variadic/typehint_error.phpt +++ b/Zend/tests/variadic/typehint_error.phpt @@ -1,5 +1,5 @@ --TEST-- -Variadic arguments enforce typehints +Variadic arguments enforce types --FILE-- <?php diff --git a/Zend/tests/variadic/typehint_suppressed_error.phpt b/Zend/tests/variadic/typehint_suppressed_error.phpt index 24109e0..ef217b2 100644 --- a/Zend/tests/variadic/typehint_suppressed_error.phpt +++ b/Zend/tests/variadic/typehint_suppressed_error.phpt @@ -1,5 +1,5 @@ --TEST-- -Error suppression for typehints on variadic arguments works +Error suppression for types on variadic arguments works --FILE-- <?php diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index f65f2ed..d3e17d0 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4416,7 +4416,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */ zend_arg_info *arg_infos; if (return_type_ast) { - /* Use op_array->arg_info[-1] for return type hinting */ + /* Use op_array->arg_info[-1] for return type */ arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children + 1, 0); arg_infos->name = NULL; arg_infos->pass_by_reference = (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0; @@ -4525,31 +4525,31 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */ && !Z_CONSTANT(default_node.u.constant) ) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with array type hint can only be an array or NULL"); + "with array type can only be an array or NULL"); } } else if (arg_info->type_hint == IS_CALLABLE && default_ast) { if (!has_null_default && !Z_CONSTANT(default_node.u.constant)) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with callable type hint can only be NULL"); + "with callable type can only be NULL"); } } } else { if (default_ast && !has_null_default && !Z_CONSTANT(default_node.u.constant)) { if (arg_info->class_name) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with a class type hint can only be NULL"); + "with a class type can only be NULL"); } else switch (arg_info->type_hint) { case IS_DOUBLE: if (Z_TYPE(default_node.u.constant) != IS_DOUBLE && Z_TYPE(default_node.u.constant) != IS_LONG) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with a float type hint can only be float, integer, or NULL"); + "with a float type can only be float, integer, or NULL"); } break; default: if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) { zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters " - "with a %s type hint can only be %s or NULL", + "with a %s type can only be %s or NULL", zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint)); } break; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index b777a0b..992d75c 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -261,7 +261,7 @@ typedef struct _zend_try_catch_element { /* class has magic methods __get/__set/__unset/__isset that use guards */ #define ZEND_ACC_USE_GUARDS 0x1000000 -/* function has arguments with type hinting */ +/* function has typed arguments */ #define ZEND_ACC_HAS_TYPE_HINTS 0x10000000 /* op_array has finally blocks */ @@ -270,7 +270,7 @@ typedef struct _zend_try_catch_element { /* internal function is allocated at arena */ #define ZEND_ACC_ARENA_ALLOCATED 0x20000000 -/* Function has a return type hint (or class has such non-private function) */ +/* Function has a return type (or class has such non-private function) */ #define ZEND_ACC_HAS_RETURN_TYPE 0x40000000 /* op_array uses strict mode types */ @@ -319,7 +319,7 @@ typedef struct _zend_arg_info { /* the following structure repeats the layout of zend_internal_arg_info, * but its fields have different meaning. It's used as the first element of * arg_info array to define properties of internal functions. - * It's also used for return type hinting. + * It's also used for the return type. */ typedef struct _zend_internal_function_info { zend_uintptr_t required_num_args; diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 73b67f5..6f897ab 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -170,7 +170,7 @@ char *zend_visibility_string(uint32_t fn_flags) /* {{{ */ static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_info *fe_arg_info, const zend_function *proto, zend_arg_info *proto_arg_info) /* {{{ */ { if (ZEND_LOG_XOR(fe_arg_info->class_name, proto_arg_info->class_name)) { - /* Only one has a type hint and the other one doesn't */ + /* Only one has a type declaration and the other one doesn't */ return 0; } @@ -239,7 +239,7 @@ static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_inf } if (fe_arg_info->type_hint != proto_arg_info->type_hint) { - /* Incompatible type hint */ + /* Incompatible type */ return 0; } diff --git a/tests/lang/type_hints_003.phpt b/tests/lang/type_hints_003.phpt index 0ef3e35..2b536d0 100644 --- a/tests/lang/type_hints_003.phpt +++ b/tests/lang/type_hints_003.phpt @@ -1,5 +1,5 @@ --TEST-- -ZE2 type hinting +ZE2 type --SKIPIF-- <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> --FILE-- @@ -11,4 +11,4 @@ class T { ?> --EXPECTF-- -Fatal error: Default value for parameters with a class type hint can only be NULL in %stype_hints_003.php on line 3 +Fatal error: Default value for parameters with a class type can only be NULL in %stype_hints_003.php on line 3