com php-src: Fix more tests, improve error messages in failure output for thrown exception: Zend/tests/typehints/scalar_none.phpt Z
end/tests/typehints/scalar_null.phpt Zend/tests/typehints /scalar_return_basic.phpt Zend/tests/typehints/scalar _strict.phpt
Zend/tests/typehints/scalar_strict_basic .phpt Zend/zend_execute.c
| From: | Dmitry Stogov | Date: | Wed, 18 Mar 2015 16:42:09 +0000 |
| Subject: | com php-src: Fix more tests, improve error messages in failure output for thrown exception: Zend/tests/typehints/scalar_none.phpt Z end/tests/typehints/scalar_null.phpt Zend/tests/typehints /scalar_return_basic.phpt Zend/tests/typehints/scalar _strict.phpt Zend/tests/typehints/scalar_strict_basic .phpt Zend/zend_execute.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85699@lists.php.net to get a copy of this message | ||
Commit: dd9f4f95858a5720f914341f36b6e60cd0706797
Author: Anthony Ferrara <ircmaxell@gmail.com> Wed, 18 Mar 2015 12:42:09 -0400
Parents: 7feebead1b70714c45bf302e0356b4cb8047fba0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dd9f4f95858a5720f914341f36b6e60cd0706797
Log:
Fix more tests, improve error messages in failure output for thrown exception
Changed paths:
M Zend/tests/typehints/scalar_none.phpt
M Zend/tests/typehints/scalar_null.phpt
M Zend/tests/typehints/scalar_return_basic.phpt
M Zend/tests/typehints/scalar_strict.phpt
M Zend/tests/typehints/scalar_strict_basic.phpt
M Zend/zend_execute.c
diff --git a/Zend/tests/typehints/scalar_none.phpt b/Zend/tests/typehints/scalar_none.phpt index 0b7f7ec..a22e874 100644 --- a/Zend/tests/typehints/scalar_none.phpt +++ b/Zend/tests/typehints/scalar_none.phpt @@ -26,25 +26,22 @@ $functions = [ foreach ($functions as $type => $function) { echo "Testing $type:", PHP_EOL; - var_dump($function()); + try { + var_dump($function()); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } +echo PHP_EOL . "Done"; --EXPECTF-- Testing int: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: i on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d and defined in %s on line %d Testing float: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: f on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d and defined in %s on line %d Testing string: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: s on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d and defined in %s on line %d Testing bool: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: b on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d and defined in %s on line %d Testing int nullable: NULL Testing float nullable: @@ -53,3 +50,5 @@ Testing string nullable: NULL Testing bool nullable: NULL + +Done \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_null.phpt b/Zend/tests/typehints/scalar_null.phpt index c5aa1ce..4ca4d39 100644 --- a/Zend/tests/typehints/scalar_null.phpt +++ b/Zend/tests/typehints/scalar_null.phpt @@ -26,21 +26,24 @@ $functions = [ foreach ($functions as $type => $function) { echo "Testing $type:", PHP_EOL; - var_dump($function(NULL)); + try { + var_dump($function(null)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } + +echo PHP_EOL . "Done"; +?> --EXPECTF-- Testing int: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined in %s on line %d Testing float: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined in %s on line %d Testing string: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined in %s on line %d Testing bool: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined in %s on line %d Testing int nullable: NULL Testing float nullable: @@ -49,3 +52,5 @@ Testing string nullable: NULL Testing bool nullable: NULL + +Done \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt index f31055e..eff1bbf 100644 --- a/Zend/tests/typehints/scalar_return_basic.phpt +++ b/Zend/tests/typehints/scalar_return_basic.phpt @@ -50,11 +50,17 @@ foreach ($functions as $type => $function) { foreach ($values as $value) { echo "*** Trying "; var_dump($value); - var_dump($function($value)); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } } ---EXPECTF-- +echo PHP_EOL . "Done"; +?> +--EXPECTF-- Testing 'int' typehint: *** Trying int(1) int(1) @@ -68,41 +74,30 @@ int(1) E_NOTICE: A non well formed numeric value encountered on line %d int(1) *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d -string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d *** Trying string(0) "" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d -string(0) "" -*** Trying int(%d) -int(%d) +*** 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) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, float returned on line %d -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 -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, array returned on line %d -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) { } -*** Trying object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, object returned on line %d -object(stdClass)#%s (0) { -} -*** Trying object(Stringable)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, object returned on line %d -object(Stringable)#%s (0) { -} -*** Trying resource(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, resource returned on line %d -resource(%d) of type (stream) +*** 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) @@ -117,13 +112,11 @@ float(1.5) E_NOTICE: A non well formed numeric value encountered on line %d float(1) *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d -string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d *** Trying string(0) "" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d -string(0) "" -*** Trying int(%d) -float(%s) +*** 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) @@ -131,26 +124,18 @@ float(1) *** Trying bool(false) float(0) *** Trying NULL -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, array returned on line %d -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) { } -*** Trying object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, object returned on line %d -object(stdClass)#%s (0) { -} -*** Trying object(Stringable)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, object returned on line %d -object(Stringable)#%s (0) { -} -*** Trying resource(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, resource returned on line %d -resource(%d) of type (stream) +*** 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) @@ -167,8 +152,8 @@ string(2) "1a" string(1) "a" *** Trying string(0) "" string(0) "" -*** Trying int(%d) -string(%d) "%d" +*** Trying int(9223372036854775807) +string(19) "9223372036854775807" *** Trying float(NAN) string(3) "NAN" *** Trying bool(true) @@ -176,24 +161,18 @@ string(1) "1" *** Trying bool(false) string(0) "" *** Trying NULL -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, array returned on line %d -array(0) { -} -*** Trying object(stdClass)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, object returned on line %d -object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { } -*** Trying object(Stringable)#%s (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(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, resource returned on line %d -resource(%d) of type (stream) +*** 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) @@ -210,7 +189,7 @@ bool(true) bool(true) *** Trying string(0) "" bool(false) -*** Trying int(%d) +*** Trying int(9223372036854775807) bool(true) *** Trying float(NAN) bool(true) @@ -219,23 +198,17 @@ bool(true) *** Trying bool(false) bool(false) *** Trying NULL -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, array returned on line %d -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) { } -*** Trying object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, object returned on line %d -object(stdClass)#%s (0) { -} -*** Trying object(Stringable)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, object returned on line %d -object(Stringable)#%s (0) { -} -*** Trying resource(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, resource returned on line %d -resource(%d) of type (stream) +*** 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 \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict.phpt b/Zend/tests/typehints/scalar_strict.phpt index b35eeba..783185a 100644 --- a/Zend/tests/typehints/scalar_strict.phpt +++ b/Zend/tests/typehints/scalar_strict.phpt @@ -49,220 +49,229 @@ $values = [ foreach ($functions as $type => $function) { echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; foreach ($values as $value) { - echo "*** Trying "; + echo PHP_EOL . "*** Trying "; var_dump($value); - var_dump($function($value)); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } } ---EXPECTF-- +echo PHP_EOL . "Done"; +?> +--EXPECTF-- Testing 'int' typehint: + *** Trying int(1) int(1) + *** Trying string(1) "1" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying float(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d -float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying float(1.5) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d -float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying string(2) "1a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(0) "" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying int(9223372036854775807) int(9223372036854775807) + *** Trying float(NAN) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d -float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying bool(true) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined on line %d -bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying bool(false) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined on line %d -bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d and defined on line %d -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 and defined in %s on line %d Testing 'float' typehint: + *** Trying int(1) float(1) + *** Trying string(1) "1" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying float(1) float(1) + *** Trying float(1.5) float(1.5) + *** Trying string(2) "1a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(0) "" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying int(9223372036854775807) float(9.2233720368548E+18) + *** Trying float(NAN) float(NAN) + *** Trying bool(true) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined on line %d -bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying bool(false) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined on line %d -bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d and defined on line %d -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 and defined in %s on line %d Testing 'string' typehint: + *** Trying int(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined on line %d -int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "1" string(1) "1" + *** Trying float(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined on line %d -float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined in %s on line %d + *** Trying float(1.5) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined on line %d -float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined 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) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined on line %d -int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float(NAN) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined on line %d -float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined in %s on line %d + *** Trying bool(true) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined on line %d -bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying bool(false) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined on line %d -bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d and defined on line %d -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 and defined in %s on line %d Testing 'bool' typehint: + *** Trying int(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined on line %d -int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "1" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying float(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined on line %d -float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying float(1.5) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined on line %d -float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying string(2) "1a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(0) "" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying int(9223372036854775807) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined on line %d -int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float(NAN) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined on line %d -float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying bool(true) bool(true) + *** Trying bool(false) bool(false) + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined on line %d -resource(5) of type (stream) \ No newline at end of file +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined in %s on line %d + +Done \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_basic.phpt b/Zend/tests/typehints/scalar_strict_basic.phpt index de96cc6..2ad00ed 100644 --- a/Zend/tests/typehints/scalar_strict_basic.phpt +++ b/Zend/tests/typehints/scalar_strict_basic.phpt @@ -10,10 +10,9 @@ $errnames = [ E_WARNING => 'E_WARNING', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' ]; -$errored = true; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames, &$errored) { + +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { echo "$errnames[$errno]: $errmsg on line $line\n"; - $errored = true; return true; }); @@ -52,91 +51,131 @@ foreach ($functions as $type => $function) { echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; foreach ($values as $value) { $errored = false; - echo "*** Trying ", type($value), " value", PHP_EOL; - $result = $function($value); - if (!$errored) { - var_dump($result); + echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL; + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; } } } +echo PHP_EOL . "Done"; +?> --EXPECTF-- - Testing 'int' typehint: + *** Trying integer value int(1) + *** Trying float value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying string value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying true value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying false value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d and defined in %s on line %d Testing 'float' typehint: + *** Trying integer value float(1) + *** Trying float value float(1) + *** Trying string value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying true value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying false value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d and defined in %s on line %d Testing 'string' typehint: + *** Trying integer value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined in %s on line %d + *** Trying string value string(1) "1" + *** Trying true value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying false value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d and defined in %s on line %d Testing 'bool' typehint: + *** Trying integer value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying string value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying true value bool(true) + *** Trying false value bool(false) + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined in %s on line %d + +Done \ No newline at end of file diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 36bf6b1..2b1a83c 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -867,8 +867,9 @@ ZEND_API void zend_verify_return_error(const zend_function *zf, const char *need fclass = ""; } - zend_type_error("Return value of %s%s%s() must %s%s, %s%s returned", - fclass, fsep, fname, need_msg, need_kind, returned_msg, returned_kind); + zend_type_error("Return value of %s%s%s() must %s%s, %s%s returned in %s on line %d", + fclass, fsep, fname, need_msg, need_kind, returned_msg, returned_kind, + zf->op_array.filename->val, EG(current_execute_data)->opline->lineno); } #if ZEND_DEBUG
diff --git a/Zend/tests/typehints/scalar_none.phpt b/Zend/tests/typehints/scalar_none.phpt index 0b7f7ec..a22e874 100644 --- a/Zend/tests/typehints/scalar_none.phpt +++ b/Zend/tests/typehints/scalar_none.phpt @@ -26,25 +26,22 @@ $functions = [ foreach ($functions as $type => $function) { echo "Testing $type:", PHP_EOL; - var_dump($function()); + try { + var_dump($function()); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } +echo PHP_EOL . "Done"; --EXPECTF-- Testing int: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: i on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, none given, called in %s on line %d and defined in %s on line %d Testing float: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: f on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, none given, called in %s on line %d and defined in %s on line %d Testing string: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: s on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, none given, called in %s on line %d and defined in %s on line %d Testing bool: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d and defined on line %d -E_NOTICE: Undefined variable: b on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, none given, called in %s on line %d and defined in %s on line %d Testing int nullable: NULL Testing float nullable: @@ -53,3 +50,5 @@ Testing string nullable: NULL Testing bool nullable: NULL + +Done \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_null.phpt b/Zend/tests/typehints/scalar_null.phpt index c5aa1ce..4ca4d39 100644 --- a/Zend/tests/typehints/scalar_null.phpt +++ b/Zend/tests/typehints/scalar_null.phpt @@ -26,21 +26,24 @@ $functions = [ foreach ($functions as $type => $function) { echo "Testing $type:", PHP_EOL; - var_dump($function(NULL)); + try { + var_dump($function(null)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } + +echo PHP_EOL . "Done"; +?> --EXPECTF-- Testing int: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined in %s on line %d Testing float: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined in %s on line %d Testing string: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined in %s on line %d Testing bool: -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined in %s on line %d Testing int nullable: NULL Testing float nullable: @@ -49,3 +52,5 @@ Testing string nullable: NULL Testing bool nullable: NULL + +Done \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt index f31055e..eff1bbf 100644 --- a/Zend/tests/typehints/scalar_return_basic.phpt +++ b/Zend/tests/typehints/scalar_return_basic.phpt @@ -50,11 +50,17 @@ foreach ($functions as $type => $function) { foreach ($values as $value) { echo "*** Trying "; var_dump($value); - var_dump($function($value)); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } } ---EXPECTF-- +echo PHP_EOL . "Done"; +?> +--EXPECTF-- Testing 'int' typehint: *** Trying int(1) int(1) @@ -68,41 +74,30 @@ int(1) E_NOTICE: A non well formed numeric value encountered on line %d int(1) *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d -string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d *** Trying string(0) "" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d -string(0) "" -*** Trying int(%d) -int(%d) +*** 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) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, float returned on line %d -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 -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, array returned on line %d -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) { } -*** Trying object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, object returned on line %d -object(stdClass)#%s (0) { -} -*** Trying object(Stringable)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, object returned on line %d -object(Stringable)#%s (0) { -} -*** Trying resource(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, resource returned on line %d -resource(%d) of type (stream) +*** 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) @@ -117,13 +112,11 @@ float(1.5) E_NOTICE: A non well formed numeric value encountered on line %d float(1) *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d -string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d *** Trying string(0) "" -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d -string(0) "" -*** Trying int(%d) -float(%s) +*** 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) @@ -131,26 +124,18 @@ float(1) *** Trying bool(false) float(0) *** Trying NULL -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, array returned on line %d -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) { } -*** Trying object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, object returned on line %d -object(stdClass)#%s (0) { -} -*** Trying object(Stringable)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, object returned on line %d -object(Stringable)#%s (0) { -} -*** Trying resource(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, resource returned on line %d -resource(%d) of type (stream) +*** 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) @@ -167,8 +152,8 @@ string(2) "1a" string(1) "a" *** Trying string(0) "" string(0) "" -*** Trying int(%d) -string(%d) "%d" +*** Trying int(9223372036854775807) +string(19) "9223372036854775807" *** Trying float(NAN) string(3) "NAN" *** Trying bool(true) @@ -176,24 +161,18 @@ string(1) "1" *** Trying bool(false) string(0) "" *** Trying NULL -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, array returned on line %d -array(0) { -} -*** Trying object(stdClass)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, object returned on line %d -object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { } -*** Trying object(Stringable)#%s (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(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, resource returned on line %d -resource(%d) of type (stream) +*** 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) @@ -210,7 +189,7 @@ bool(true) bool(true) *** Trying string(0) "" bool(false) -*** Trying int(%d) +*** Trying int(9223372036854775807) bool(true) *** Trying float(NAN) bool(true) @@ -219,23 +198,17 @@ bool(true) *** Trying bool(false) bool(false) *** Trying NULL -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, null returned on line %d -NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d *** Trying array(0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, array returned on line %d -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) { } -*** Trying object(stdClass)#%s (0) { +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, object returned on line %d -object(stdClass)#%s (0) { -} -*** Trying object(Stringable)#%s (0) { -} -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, object returned on line %d -object(Stringable)#%s (0) { -} -*** Trying resource(%d) of type (stream) -E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, resource returned on line %d -resource(%d) of type (stream) +*** 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 \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict.phpt b/Zend/tests/typehints/scalar_strict.phpt index b35eeba..783185a 100644 --- a/Zend/tests/typehints/scalar_strict.phpt +++ b/Zend/tests/typehints/scalar_strict.phpt @@ -49,220 +49,229 @@ $values = [ foreach ($functions as $type => $function) { echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; foreach ($values as $value) { - echo "*** Trying "; + echo PHP_EOL . "*** Trying "; var_dump($value); - var_dump($function($value)); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } } } ---EXPECTF-- +echo PHP_EOL . "Done"; +?> +--EXPECTF-- Testing 'int' typehint: + *** Trying int(1) int(1) + *** Trying string(1) "1" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying float(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d -float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying float(1.5) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d -float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying string(2) "1a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(0) "" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined on line %d -string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying int(9223372036854775807) int(9223372036854775807) + *** Trying float(NAN) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined on line %d -float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying bool(true) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined on line %d -bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying bool(false) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined on line %d -bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d and defined on line %d -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 and defined in %s on line %d Testing 'float' typehint: + *** Trying int(1) float(1) + *** Trying string(1) "1" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying float(1) float(1) + *** Trying float(1.5) float(1.5) + *** Trying string(2) "1a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(0) "" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined on line %d -string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying int(9223372036854775807) float(9.2233720368548E+18) + *** Trying float(NAN) float(NAN) + *** Trying bool(true) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined on line %d -bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying bool(false) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined on line %d -bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d and defined on line %d -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 and defined in %s on line %d Testing 'string' typehint: + *** Trying int(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined on line %d -int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "1" string(1) "1" + *** Trying float(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined on line %d -float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined in %s on line %d + *** Trying float(1.5) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined on line %d -float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined 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) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined on line %d -int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float(NAN) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined on line %d -float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined in %s on line %d + *** Trying bool(true) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined on line %d -bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying bool(false) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined on line %d -bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d and defined on line %d -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 and defined in %s on line %d Testing 'bool' typehint: + *** Trying int(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined on line %d -int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "1" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying float(1) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined on line %d -float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying float(1.5) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined on line %d -float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying string(2) "1a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(1) "a" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying string(0) "" -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined on line %d -string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying int(9223372036854775807) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined on line %d -int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float(NAN) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined on line %d -float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying bool(true) bool(true) + *** Trying bool(false) bool(false) + *** Trying NULL -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined on line %d -NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined in %s on line %d + *** Trying array(0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined on line %d -array(0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined in %s on line %d + *** Trying object(stdClass)#6 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined on line %d -object(stdClass)#6 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined in %s on line %d + *** Trying object(Stringable)#7 (0) { } -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined on line %d -object(Stringable)#7 (0) { -} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource(5) of type (stream) -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined on line %d -resource(5) of type (stream) \ No newline at end of file +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined in %s on line %d + +Done \ No newline at end of file diff --git a/Zend/tests/typehints/scalar_strict_basic.phpt b/Zend/tests/typehints/scalar_strict_basic.phpt index de96cc6..2ad00ed 100644 --- a/Zend/tests/typehints/scalar_strict_basic.phpt +++ b/Zend/tests/typehints/scalar_strict_basic.phpt @@ -10,10 +10,9 @@ $errnames = [ E_WARNING => 'E_WARNING', E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' ]; -$errored = true; -set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames, &$errored) { + +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { echo "$errnames[$errno]: $errmsg on line $line\n"; - $errored = true; return true; }); @@ -52,91 +51,131 @@ foreach ($functions as $type => $function) { echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; foreach ($values as $value) { $errored = false; - echo "*** Trying ", type($value), " value", PHP_EOL; - $result = $function($value); - if (!$errored) { - var_dump($result); + echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL; + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; } } } +echo PHP_EOL . "Done"; +?> --EXPECTF-- - Testing 'int' typehint: + *** Trying integer value int(1) + *** Trying float value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d and defined in %s on line %d + *** Trying string value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d + *** Trying true value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying false value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line 53 and defined on line 18 +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d and defined in %s on line %d Testing 'float' typehint: + *** Trying integer value float(1) + *** Trying float value float(1) + *** Trying string value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d and defined in %s on line %d + *** Trying true value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying false value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line 53 and defined on line 19 +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d and defined in %s on line %d Testing 'string' typehint: + *** Trying integer value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d and defined in %s on line %d + *** Trying string value string(1) "1" + *** Trying true value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying false value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d and defined in %s on line %d + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line 53 and defined on line 20 +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d and defined in %s on line %d Testing 'bool' typehint: + *** Trying integer value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d and defined in %s on line %d + *** Trying float value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d and defined in %s on line %d + *** Trying string value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d and defined in %s on line %d + *** Trying true value bool(true) + *** Trying false value bool(false) + *** Trying null value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d and defined in %s on line %d + *** Trying array value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d and defined in %s on line %d + *** Trying object value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d and defined in %s on line %d + *** Trying resource value -E_RECOVERABLE_ERROR: Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line 53 and defined on line 21 +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d and defined in %s on line %d + +Done \ No newline at end of file diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 36bf6b1..2b1a83c 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -867,8 +867,9 @@ ZEND_API void zend_verify_return_error(const zend_function *zf, const char *need fclass = ""; } - zend_type_error("Return value of %s%s%s() must %s%s, %s%s returned", - fclass, fsep, fname, need_msg, need_kind, returned_msg, returned_kind); + zend_type_error("Return value of %s%s%s() must %s%s, %s%s returned in %s on line %d", + fclass, fsep, fname, need_msg, need_kind, returned_msg, returned_kind, + zf->op_array.filename->val, EG(current_execute_data)->opline->lineno); } #if ZEND_DEBUG