Fix more tests, improve error messages in failure output for thrown exception

This commit is contained in:
Anthony Ferrara 2015-03-18 12:42:09 -04:00
parent 7feebead1b
commit dd9f4f9585
6 changed files with 285 additions and 259 deletions

View File

@ -26,25 +26,22 @@ $functions = [
foreach ($functions as $type => $function) { foreach ($functions as $type => $function) {
echo "Testing $type:", PHP_EOL; 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-- --EXPECTF--
Testing int: 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 *** 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
E_NOTICE: Undefined variable: i on line %d
NULL
Testing float: 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 *** 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
E_NOTICE: Undefined variable: f on line %d
NULL
Testing string: 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 *** 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
E_NOTICE: Undefined variable: s on line %d
NULL
Testing bool: 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 *** 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
E_NOTICE: Undefined variable: b on line %d
NULL
Testing int nullable: Testing int nullable:
NULL NULL
Testing float nullable: Testing float nullable:
@ -53,3 +50,5 @@ Testing string nullable:
NULL NULL
Testing bool nullable: Testing bool nullable:
NULL NULL
Done

View File

@ -26,21 +26,24 @@ $functions = [
foreach ($functions as $type => $function) { foreach ($functions as $type => $function) {
echo "Testing $type:", PHP_EOL; 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-- --EXPECTF--
Testing int: 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 *** 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
NULL
Testing float: 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 *** 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
NULL
Testing string: 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 *** 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
NULL
Testing bool: 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 *** 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
NULL
Testing int nullable: Testing int nullable:
NULL NULL
Testing float nullable: Testing float nullable:
@ -49,3 +52,5 @@ Testing string nullable:
NULL NULL
Testing bool nullable: Testing bool nullable:
NULL NULL
Done

View File

@ -50,11 +50,17 @@ foreach ($functions as $type => $function) {
foreach ($values as $value) { foreach ($values as $value) {
echo "*** Trying "; echo "*** Trying ";
var_dump($value); 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: Testing 'int' typehint:
*** Trying int(1) *** Trying int(1)
int(1) int(1)
@ -68,41 +74,30 @@ int(1)
E_NOTICE: A non well formed numeric value encountered on line %d E_NOTICE: A non well formed numeric value encountered on line %d
int(1) int(1)
*** Trying string(1) "a" *** Trying string(1) "a"
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d *** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d
string(1) "a"
*** Trying string(0) "" *** Trying string(0) ""
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, string returned on line %d *** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d
string(0) "" *** Trying int(9223372036854775807)
*** Trying int(%d) int(9223372036854775807)
int(%d)
*** Trying float(NAN) *** Trying float(NAN)
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, float returned on line %d *** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d
float(NAN)
*** Trying bool(true) *** Trying bool(true)
int(1) int(1)
*** Trying bool(false) *** Trying bool(false)
int(0) int(0)
*** Trying NULL *** Trying NULL
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, null returned on line %d *** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d
NULL
*** Trying array(0) { *** Trying array(0) {
} }
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type integer, array returned on line %d *** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d
array(0) { *** 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 *** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d
object(stdClass)#%s (0) { *** Trying resource(5) of type (stream)
} *** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d
*** 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)
Testing 'float' typehint: Testing 'float' typehint:
*** Trying int(1) *** Trying int(1)
@ -117,13 +112,11 @@ float(1.5)
E_NOTICE: A non well formed numeric value encountered on line %d E_NOTICE: A non well formed numeric value encountered on line %d
float(1) float(1)
*** Trying string(1) "a" *** Trying string(1) "a"
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d *** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d
string(1) "a"
*** Trying string(0) "" *** Trying string(0) ""
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, string returned on line %d *** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d
string(0) "" *** Trying int(9223372036854775807)
*** Trying int(%d) float(9.2233720368548E+18)
float(%s)
*** Trying float(NAN) *** Trying float(NAN)
float(NAN) float(NAN)
*** Trying bool(true) *** Trying bool(true)
@ -131,26 +124,18 @@ float(1)
*** Trying bool(false) *** Trying bool(false)
float(0) float(0)
*** Trying NULL *** Trying NULL
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, null returned on line %d *** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d
NULL
*** Trying array(0) { *** Trying array(0) {
} }
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type float, array returned on line %d *** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d
array(0) { *** 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 *** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d
object(stdClass)#%s (0) { *** Trying resource(5) of type (stream)
} *** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d
*** 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)
Testing 'string' typehint: Testing 'string' typehint:
*** Trying int(1) *** Trying int(1)
@ -167,8 +152,8 @@ string(2) "1a"
string(1) "a" string(1) "a"
*** Trying string(0) "" *** Trying string(0) ""
string(0) "" string(0) ""
*** Trying int(%d) *** Trying int(9223372036854775807)
string(%d) "%d" string(19) "9223372036854775807"
*** Trying float(NAN) *** Trying float(NAN)
string(3) "NAN" string(3) "NAN"
*** Trying bool(true) *** Trying bool(true)
@ -176,24 +161,18 @@ string(1) "1"
*** Trying bool(false) *** Trying bool(false)
string(0) "" string(0) ""
*** Trying NULL *** Trying NULL
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, null returned on line %d *** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d
NULL
*** Trying array(0) { *** Trying array(0) {
} }
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, array returned on line %d *** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d
array(0) { *** Trying object(stdClass)#6 (0) {
} }
*** Trying object(stdClass)#%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) {
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, object returned on line %d
object(stdClass)#%s (0) {
}
*** Trying object(Stringable)#%s (0) {
} }
string(6) "foobar" string(6) "foobar"
*** Trying resource(%d) of type (stream) *** Trying resource(5) of type (stream)
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type string, resource returned on line %d *** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d
resource(%d) of type (stream)
Testing 'bool' typehint: Testing 'bool' typehint:
*** Trying int(1) *** Trying int(1)
@ -210,7 +189,7 @@ bool(true)
bool(true) bool(true)
*** Trying string(0) "" *** Trying string(0) ""
bool(false) bool(false)
*** Trying int(%d) *** Trying int(9223372036854775807)
bool(true) bool(true)
*** Trying float(NAN) *** Trying float(NAN)
bool(true) bool(true)
@ -219,23 +198,17 @@ bool(true)
*** Trying bool(false) *** Trying bool(false)
bool(false) bool(false)
*** Trying NULL *** Trying NULL
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, null returned on line %d *** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d
NULL
*** Trying array(0) { *** Trying array(0) {
} }
E_RECOVERABLE_ERROR: Return value of {closure}() must be of the type boolean, array returned on line %d *** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d
array(0) { *** 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 *** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d
object(stdClass)#%s (0) { *** Trying resource(5) of type (stream)
} *** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d
*** Trying object(Stringable)#%s (0) {
} Done
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)

View File

@ -49,220 +49,229 @@ $values = [
foreach ($functions as $type => $function) { foreach ($functions as $type => $function) {
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
foreach ($values as $value) { foreach ($values as $value) {
echo "*** Trying "; echo PHP_EOL . "*** Trying ";
var_dump($value); 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: Testing 'int' typehint:
*** Trying int(1) *** Trying int(1)
int(1) int(1)
*** Trying string(1) "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 *** 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
string(1) "1"
*** Trying float(1) *** 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 *** 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
float(1)
*** Trying float(1.5) *** 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 *** 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
float(1.5)
*** Trying string(2) "1a" *** 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 *** 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
string(2) "1a"
*** Trying string(1) "a" *** 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 *** 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
string(1) "a"
*** Trying string(0) "" *** 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 *** 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
string(0) ""
*** Trying int(9223372036854775807) *** Trying int(9223372036854775807)
int(9223372036854775807) int(9223372036854775807)
*** Trying float(NAN) *** 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 *** 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
float(NAN)
*** Trying bool(true) *** 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 *** 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
bool(true)
*** Trying bool(false) *** 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 *** 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
bool(false)
*** Trying NULL *** 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 *** 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
NULL
*** Trying array(0) { *** 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 *** 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
array(0) {
}
*** Trying object(stdClass)#6 (0) { *** 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 *** 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
object(stdClass)#6 (0) {
}
*** Trying object(Stringable)#7 (0) { *** 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 *** 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
object(Stringable)#7 (0) {
}
*** Trying resource(5) of type (stream) *** 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 *** 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
resource(5) of type (stream)
Testing 'float' typehint: Testing 'float' typehint:
*** Trying int(1) *** Trying int(1)
float(1) float(1)
*** Trying string(1) "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 *** 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
string(1) "1"
*** Trying float(1) *** Trying float(1)
float(1) float(1)
*** Trying float(1.5) *** Trying float(1.5)
float(1.5) float(1.5)
*** Trying string(2) "1a" *** 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 *** 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
string(2) "1a"
*** Trying string(1) "a" *** 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 *** 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
string(1) "a"
*** Trying string(0) "" *** 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 *** 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
string(0) ""
*** Trying int(9223372036854775807) *** Trying int(9223372036854775807)
float(9.2233720368548E+18) float(9.2233720368548E+18)
*** Trying float(NAN) *** Trying float(NAN)
float(NAN) float(NAN)
*** Trying bool(true) *** 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 *** 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
bool(true)
*** Trying bool(false) *** 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 *** 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
bool(false)
*** Trying NULL *** 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 *** 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
NULL
*** Trying array(0) { *** 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 *** 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
array(0) {
}
*** Trying object(stdClass)#6 (0) { *** 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 *** 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
object(stdClass)#6 (0) {
}
*** Trying object(Stringable)#7 (0) { *** 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 *** 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
object(Stringable)#7 (0) {
}
*** Trying resource(5) of type (stream) *** 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 *** 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
resource(5) of type (stream)
Testing 'string' typehint: Testing 'string' typehint:
*** Trying int(1) *** 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 *** 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
int(1)
*** Trying string(1) "1" *** Trying string(1) "1"
string(1) "1" string(1) "1"
*** Trying float(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 *** 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
float(1)
*** Trying float(1.5) *** 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 *** 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
float(1.5)
*** Trying string(2) "1a" *** Trying string(2) "1a"
string(2) "1a" string(2) "1a"
*** Trying string(1) "a" *** Trying string(1) "a"
string(1) "a" string(1) "a"
*** Trying string(0) "" *** Trying string(0) ""
string(0) "" string(0) ""
*** Trying int(9223372036854775807) *** 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 *** 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
int(9223372036854775807)
*** Trying float(NAN) *** 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 *** 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
float(NAN)
*** Trying bool(true) *** 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 *** 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
bool(true)
*** Trying bool(false) *** 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 *** 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
bool(false)
*** Trying NULL *** 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 *** 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
NULL
*** Trying array(0) { *** 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 *** 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
array(0) {
}
*** Trying object(stdClass)#6 (0) { *** 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 *** 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
object(stdClass)#6 (0) {
}
*** Trying object(Stringable)#7 (0) { *** 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 *** 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
object(Stringable)#7 (0) {
}
*** Trying resource(5) of type (stream) *** 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 *** 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
resource(5) of type (stream)
Testing 'bool' typehint: Testing 'bool' typehint:
*** Trying int(1) *** 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 *** 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
int(1)
*** Trying string(1) "1" *** 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 *** 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
string(1) "1"
*** Trying float(1) *** 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 *** 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
float(1)
*** Trying float(1.5) *** 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 *** 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
float(1.5)
*** Trying string(2) "1a" *** 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 *** 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
string(2) "1a"
*** Trying string(1) "a" *** 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 *** 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
string(1) "a"
*** Trying string(0) "" *** 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 *** 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
string(0) ""
*** Trying int(9223372036854775807) *** 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 *** 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
int(9223372036854775807)
*** Trying float(NAN) *** 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 *** 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
float(NAN)
*** Trying bool(true) *** Trying bool(true)
bool(true) bool(true)
*** Trying bool(false) *** Trying bool(false)
bool(false) bool(false)
*** Trying NULL *** 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 *** 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
NULL
*** Trying array(0) { *** 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 *** 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
array(0) {
}
*** Trying object(stdClass)#6 (0) { *** 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 *** 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
object(stdClass)#6 (0) {
}
*** Trying object(Stringable)#7 (0) { *** 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 *** 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
object(Stringable)#7 (0) {
}
*** Trying resource(5) of type (stream) *** 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 *** 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
resource(5) of type (stream)
Done

View File

@ -10,10 +10,9 @@ $errnames = [
E_WARNING => 'E_WARNING', E_WARNING => 'E_WARNING',
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' 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"; echo "$errnames[$errno]: $errmsg on line $line\n";
$errored = true;
return true; return true;
}); });
@ -52,91 +51,131 @@ foreach ($functions as $type => $function) {
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
foreach ($values as $value) { foreach ($values as $value) {
$errored = false; $errored = false;
echo "*** Trying ", type($value), " value", PHP_EOL; echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL;
$result = $function($value); try {
if (!$errored) { var_dump($function($value));
var_dump($result); } catch (TypeException $e) {
echo "*** Caught " . $e->getMessage() . PHP_EOL;
} }
} }
} }
echo PHP_EOL . "Done";
?>
--EXPECTF-- --EXPECTF--
Testing 'int' typehint: Testing 'int' typehint:
*** Trying integer value *** Trying integer value
int(1) int(1)
*** Trying float value *** 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 *** 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 *** 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 *** 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 *** 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 *** 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 *** 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 *** 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: Testing 'float' typehint:
*** Trying integer value *** Trying integer value
float(1) float(1)
*** Trying float value *** Trying float value
float(1) float(1)
*** Trying string value *** 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 *** 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 *** 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 *** 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 *** 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 *** 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 *** 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: Testing 'string' typehint:
*** Trying integer value *** 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 *** 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 *** Trying string value
string(1) "1" string(1) "1"
*** Trying true value *** 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 *** 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 *** 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 *** 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 *** 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 *** 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: Testing 'bool' typehint:
*** Trying integer value *** 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 *** 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 *** 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 *** Trying true value
bool(true) bool(true)
*** Trying false value *** Trying false value
bool(false) bool(false)
*** Trying null value *** 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 *** 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 *** 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 *** 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

View File

@ -867,8 +867,9 @@ ZEND_API void zend_verify_return_error(const zend_function *zf, const char *need
fclass = ""; fclass = "";
} }
zend_type_error("Return value of %s%s%s() must %s%s, %s%s returned", 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); 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 #if ZEND_DEBUG