From 18f376d7e20f2513fc0da5fbc023f1e7042ae077 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 22 Jan 2016 03:41:33 +0100 Subject: [PATCH] PresenterComponentReflection::convertType() NULLs are not allowed --- src/Application/UI/PresenterComponentReflection.php | 5 +---- .../UI/PresenterComponentReflection.convertType.phpt | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Application/UI/PresenterComponentReflection.php b/src/Application/UI/PresenterComponentReflection.php index 9ef2219c4..18901fbf7 100644 --- a/src/Application/UI/PresenterComponentReflection.php +++ b/src/Application/UI/PresenterComponentReflection.php @@ -166,13 +166,10 @@ public static function convertType(& $val, $type, $isClass = FALSE) } elseif ($type === 'NULL') { // means 'not array' return !is_array($val); - } elseif ($val === NULL) { - settype($val, $type); // to scalar or array - } elseif ($type === 'array') { return is_array($val); - } elseif (!is_scalar($val)) { // array, resource, etc. + } elseif (!is_scalar($val)) { // array, resource, NULL, etc. return FALSE; } else { diff --git a/tests/UI/PresenterComponentReflection.convertType.phpt b/tests/UI/PresenterComponentReflection.convertType.phpt index 58724e3ab..44718c6e9 100644 --- a/tests/UI/PresenterComponentReflection.convertType.phpt +++ b/tests/UI/PresenterComponentReflection.convertType.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; // [$type] null scalar array object callable // [$val] ---------------------------------------------------------- -// null pass cast cast deny deny +// null deny deny deny deny deny // scalar pass cast/deny deny deny deny // array deny deny pass deny deny // object pass deny deny pass/deny deny @@ -33,7 +33,7 @@ function testIt($type, $val, $res = NULL) $obj = new stdClass; -testIt('string', NULL, ''); +testIt('string', NULL); testIt('string', []); testIt('string', $obj); testIt('string', '', ''); @@ -50,7 +50,7 @@ testIt('string', 1, '1'); testIt('string', 1.0, '1'); testIt('string', 1.2, '1.2'); -testIt('int', NULL, 0); +testIt('int', NULL); testIt('int', []); testIt('int', $obj); testIt('int', ''); @@ -67,7 +67,7 @@ testIt('int', 1, 1); testIt('int', 1.0, 1); testIt('int', 1.2); -testIt('double', NULL, 0.0); +testIt('double', NULL); testIt('double', []); testIt('double', $obj); testIt('double', ''); @@ -84,7 +84,7 @@ testIt('double', 1, 1.0); testIt('double', 1.0, 1.0); testIt('double', 1.2, 1.2); -testIt('bool', NULL, FALSE); +testIt('bool', NULL); testIt('bool', []); testIt('bool', $obj); testIt('bool', ''); @@ -100,7 +100,7 @@ testIt('bool', 1, TRUE); testIt('bool', 1.0, TRUE); testIt('bool', 1.2); -testIt('array', NULL, []); +testIt('array', NULL); testIt('array', [], []); testIt('array', $obj); testIt('array', '');