Use boolean value in return from a rest controller.
return [
'success' => false,
'data' => [
'reason' => 'No authentication configured.',
]
];
<response>
<success>0</success>
<data>
<reason>No authentication configured.</reason>
</data>
</response>
In case of true value I see 1 returned. I expected to see 0 returned for false. Would it be more correct or empty value is correct enough?
I understand that PHP itself converts false to an empty string. I'm trying to question from the XML consumer side what is the desired output format.
<response>
<success></success>
<data>
<reason>No authentication configured.</reason>
</data>
</response>
| Q | A |
| --- | --- |
| Yii version | 2.0.x |
| PHP version | any |
| Operating system | any |
Whats about something like
$child->appendChild(new DOMText((string) ($value === false ? '0' : $value)));
Sounds OK to me. @yiisoft/core-developers ?
with respect to https://www.w3.org/TR/xmlschema11-2/#boolean, the following options are prescribed:
with respect to readibility and ambiguity, I would choose for true or false, since the return of 1 in consoles actually mean an error.
@nanodesu88 correct place
I would like to see 'true' and 'false' too. Thats what I actually expected :)
Should be very small fix!
if ($value === true) {
$value = 'true';
} elseif ($value === false) {
$value = 'false';
}
$child->appendChild(new DOMText((string) $value);
^ nvm, i am just testing some github behaviors
Fixed.
Most helpful comment
with respect to https://www.w3.org/TR/xmlschema11-2/#boolean, the following options are prescribed:
with respect to readibility and ambiguity, I would choose for true or false, since the return of 1 in consoles actually mean an error.