The expression return (string)$httpValue returns the type string which is incompatible with the return type mandated by Bdf\Form\Leaf\LeafElement::toPhp() of Bdf\Form\Leaf\T|null.
In the issue above, the returned value is violating the contract defined by the
mentioned interface.
Let's take a look at an example:
interfaceHasName{/** @return string */publicfunctiongetName();}className{public$name;}classUserimplementsHasName{/** @return string|Name */publicfunctiongetName(){returnnewName('foo');// This is a violation of the ``HasName`` interface// which only allows a string value to be returned.}}
Loading history...
27
}
28
29
/**
30
* {@inheritdoc}
31
*/
32
37
protected function toHttp($phpValue): ?string
33
{
34
37
return $phpValue;
35
}
36
37
/**
38
* {@inheritdoc}
39
*/
40
81
protected function tryCast($value): ?string
41
{
42
81
if ($value === null) {
43
7
return null;
44
}
45
46
79
if (!is_scalar($value) && (!is_object($value) || !method_exists($value, '__toString'))) {
47
3
throw new TypeError('The import()\'ed value of a '.static::class.' must be stringable or null');
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: