Skip to content

Commit

Permalink
PresenterComponentReflection::convertType() NULLs are not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 22, 2016
1 parent 05259e7 commit 3fe619f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/Application/UI/PresenterComponentReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions tests/UI/PresenterComponentReflection.convertType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php';

// [$type] null scalar array object callable
// [$val] ----------------------------------------------------------
// null pass cast cast deny deny
// null pass deny deny deny deny
// scalar pass cast/deny deny deny deny
// array deny deny pass deny deny
// object pass deny deny pass/deny deny
Expand Down Expand Up @@ -50,7 +50,7 @@ testIt('NULL', 1, 1);
testIt('NULL', 1.0, 1.0);
testIt('NULL', 1.2, 1.2);

testIt('string', NULL, '');
testIt('string', NULL);
testIt('string', []);
testIt('string', $obj);
testIt('string', '', '');
Expand All @@ -67,7 +67,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', '');
Expand All @@ -84,7 +84,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', '');
Expand All @@ -101,7 +101,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', '');
Expand All @@ -117,7 +117,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', '');
Expand Down

0 comments on commit 3fe619f

Please sign in to comment.