Skip to content

Commit 692dfa1

Browse files
committed
PresenterComponentReflection::convertType() converts NULL to appropriate type
It is not BC break because convertType was never used with NULL.
1 parent d9b6a39 commit 692dfa1

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/Application/UI/PresenterComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function saveState(array & $params, $reflection = NULL)
154154
} elseif (array_key_exists($name, $params)) { // NULLs are skipped
155155
continue;
156156

157-
} elseif (!isset($meta['since']) || $this instanceof $meta['since']) {
157+
} elseif ((!isset($meta['since']) || $this instanceof $meta['since']) && isset($this->$name)) {
158158
$params[$name] = $this->$name; // object property value
159159

160160
} else {

src/Application/UI/PresenterComponentReflection.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,16 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
143143
*/
144144
public static function convertType(& $val, $type)
145145
{
146-
if ($val === NULL || is_object($val)) {
146+
if ($val === NULL) {
147+
settype($val, $type);
148+
149+
} elseif (is_object($val)) {
147150
// ignore
151+
148152
} elseif ($type === 'array') {
149-
if (!is_array($val)) {
150-
return FALSE;
151-
}
152-
} elseif (!is_scalar($val)) {
153+
return is_array($val);
154+
155+
} elseif (!is_scalar($val)) { // array, resource, etc.
153156
return FALSE;
154157

155158
} elseif ($type !== 'NULL') {

tests/Application/PresenterComponentReflection.convertType.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php';
1313

1414
// [$type] null scalar array object* callable*
1515
// [$val] ----------------------------------------------------------
16-
// null (not used)
16+
// null (not used) pass cast cast error error
1717
// scalar pass cast/deny deny error error
1818
// array deny deny pass deny deny
1919
// object pass pass error pass/error pass/error
@@ -34,7 +34,7 @@ function testIt($type, $val, $res = NULL)
3434

3535
$obj = new stdClass;
3636

37-
testIt('string', NULL, NULL);
37+
testIt('string', NULL, '');
3838
testIt('string', []);
3939
testIt('string', $obj, $obj);
4040
testIt('string', '', '');
@@ -51,7 +51,7 @@ testIt('string', 1, '1');
5151
testIt('string', 1.0, '1');
5252
testIt('string', 1.2, '1.2');
5353

54-
testIt('int', NULL, NULL);
54+
testIt('int', NULL, 0);
5555
testIt('int', []);
5656
testIt('int', $obj, $obj);
5757
testIt('int', '');
@@ -68,7 +68,7 @@ testIt('int', 1, 1);
6868
testIt('int', 1.0, 1);
6969
testIt('int', 1.2);
7070

71-
testIt('double', NULL, NULL);
71+
testIt('double', NULL, 0.0);
7272
testIt('double', []);
7373
testIt('double', $obj, $obj);
7474
testIt('double', '');
@@ -85,7 +85,7 @@ testIt('double', 1, 1.0);
8585
testIt('double', 1.0, 1.0);
8686
testIt('double', 1.2, 1.2);
8787

88-
testIt('bool', NULL, NULL);
88+
testIt('bool', NULL, FALSE);
8989
testIt('bool', []);
9090
testIt('bool', $obj, $obj);
9191
testIt('bool', '');
@@ -101,7 +101,7 @@ testIt('bool', 1, TRUE);
101101
testIt('bool', 1.0, TRUE);
102102
testIt('bool', 1.2);
103103

104-
testIt('array', NULL, NULL);
104+
testIt('array', NULL, []);
105105
testIt('array', [], []);
106106
testIt('array', $obj, $obj);
107107
testIt('array', '');

0 commit comments

Comments
 (0)