]> granicus.if.org Git - php/commitdiff
Fix more tests, improve error messages in failure output for thrown exception
authorAnthony Ferrara <ircmaxell@gmail.com>
Wed, 18 Mar 2015 16:42:09 +0000 (12:42 -0400)
committerAnthony Ferrara <ircmaxell@gmail.com>
Wed, 18 Mar 2015 16:42:09 +0000 (12:42 -0400)
Zend/tests/typehints/scalar_none.phpt
Zend/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

index 0b7f7ec9a202fbf5440987ea3216f52d45d8efff..a22e87442eb82d343e7ffd77951f4a99ee32cd6f 100644 (file)
@@ -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
index c5aa1ce986c36cd01f7dca3f56e0e84280fc2c6f..4ca4d3932a13d35ebd15281804e126fdb6560509 100644 (file)
@@ -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
index f31055ee56e1c9e29c4f54f29ba173ce9837dcb1..eff1bbf066d0c07c340a0ff655f8cf9518fe7897 100644 (file)
@@ -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
index b35eebaa5530ae79f68eb2339e4b941a4075f330..783185a776af3a13f49cb37bf80a81dcdf601f3d 100644 (file)
@@ -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
index de96cc6ee6817de31ca74caac8c05e94c4ace9da..2ad00ed39d1cb8bd3d2235373f726eea0a463f5d 100644 (file)
@@ -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
index 36bf6b1bea9fefc84ba394a0701de2e89c03a836..2b1a83c20e5337cbd9d7487393ecc8e9aa58d882 100644 (file)
@@ -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