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...
29
}
30
31
/**
32
* {@inheritdoc}
33
*/
34
38
protected function toHttp($phpValue): ?string
35
{
36
38
return $phpValue;
37
}
38
39
/**
40
* {@inheritdoc}
41
*
42
* @return string|null
43
*/
44
82
protected function tryCast($value): ?string
45
{
46
82
if ($value === null) {
47
7
return null;
48
}
49
50
80
if (!is_scalar($value) && (!is_object($value) || !method_exists($value, '__toString'))) {
51
3
throw new TypeError('The import()\'ed value of a '.static::class.' must be stringable or null');