sveneld commented on code in PR #3787:
URL: https://github.com/apache/thrift/pull/3787#discussion_r3999882065
##########
lib/php/lib/Base/TBase.php:
##########
@@ -349,8 +349,24 @@ private function writeList(array $var, array $spec,
TProtocol $output, bool $set
} else {
$xfer += $output->writeListBegin($etype, count($var));
}
+ $setUsesValues = false;
+ if ($set && array_is_list($var)) {
+ // Preserve the legacy `element => true` marker form when every
+ // value is `true`. This keeps ambiguous `set<bool>` inputs such
+ // as `[true]` on the backward-compatible path.
+
+ foreach ($var as $candidate) {
+ if ($candidate !== true) {
+ $setUsesValues = true;
+ break;
+ }
+ }
+ }
foreach ($var as $key => $val) {
- $elem = $set ? $key : $val;
+ $elem = $set && !$setUsesValues ? $key : $val;
+ if ($set && !$setUsesValues && $etype === TType::BOOL) {
+ $elem = (bool) $elem;
Review Comment:
Addressed in both shared helpers: legacy keys are now cast according to the
declared scalar type (bool, integer, double, string/UUID), consistently with
the generated serializer. Added a regression test for a numeric-string legacy
set key in each helper; both failed with TypeError before the fix and pass
afterward.
##########
lib/php/lib/Exception/TException.php:
##########
@@ -348,8 +348,24 @@ private function writeList(array $var, array $spec,
TProtocol $output, bool $set
} else {
$xfer += $output->writeListBegin($etype, count($var));
}
+ $setUsesValues = false;
+ if ($set && array_is_list($var)) {
+ // Preserve the legacy `element => true` marker form when every
+ // value is `true`. This keeps ambiguous `set<bool>` inputs such
+ // as `[true]` on the backward-compatible path.
+
+ foreach ($var as $candidate) {
+ if ($candidate !== true) {
+ $setUsesValues = true;
+ break;
+ }
+ }
+ }
foreach ($var as $key => $val) {
- $elem = $set ? $key : $val;
+ $elem = $set && !$setUsesValues ? $key : $val;
+ if ($set && !$setUsesValues && $etype === TType::BOOL) {
+ $elem = (bool) $elem;
+ }
Review Comment:
Addressed in both shared helpers: legacy keys are now cast according to the
declared scalar type (bool, integer, double, string/UUID), consistently with
the generated serializer. Added a regression test for a numeric-string legacy
set key in each helper; both failed with TypeError before the fix and pass
afterward.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]