You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King III (JIRA)" <ji...@apache.org> on 2019/02/01 05:30:00 UTC
[jira] [Commented] (THRIFT-4070) Generated PHP for Thrift sets are
incompatible with PHP
[ https://issues.apache.org/jira/browse/THRIFT-4070?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16757986#comment-16757986 ]
James E. King III commented on THRIFT-4070:
-------------------------------------------
Pull requests are welcome here to resolve this, starting with a unit test for php that shows the problem in trying to use generated code.
> Generated PHP for Thrift sets are incompatible with PHP
> -------------------------------------------------------
>
> Key: THRIFT-4070
> URL: https://issues.apache.org/jira/browse/THRIFT-4070
> Project: Thrift
> Issue Type: Bug
> Components: PHP - Compiler
> Reporter: David Reiman
> Priority: Major
>
> In the `TBase` class that all Thrift generated code inherits from, there is a `_writeList` method that takes a boolean of whether or not the "list" in question is a set. The assumption here is that since PHP has no built-in Set data type, we can duplicate the uniqueness constraint of Sets by looking at the keys of a PHP associative array. Here's the associated code in `_writeList`:
> ```
> foreach ($var as $key => $val) {
> $elem = $set ? $key : $val;
> if (isset($ewrite)) {
> $xfer += $output->$ewrite($elem);
> } else {
> switch ($etype) {
> case TType::STRUCT:
> $xfer += $elem->write($output);
> break;
> ```
> I want to point out again that if we're using a `TType::SET`, the `$set` variable will be `true`, and `$elem` will be the `$key`, not the `$value`. Here's the problem, from PHP array documentation (http://php.net/manual/en/language.types.array.php):
> "The key can either be an integer or a string. The value can be of any type...Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type."
> In other words, it is impossible to implement a Thrift set of anything other than strings or integers given the current implementation of PHP generated code.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)