Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-342

PHP: can't have sets of complex types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.7
    • None
    • SVN trunk r743881

    Description

      A setup like this:

      struct alice {
      1: string bob
      }

      and another like this:

      struct charlie {
      1: set<alice> david
      }

      causes problems because the generated PHP code looks like:

      ==
      case 1:
      if ($ftype == TType::SET) {
      $this->david = array();
      $_size0 = 0;
      $_etype3 = 0;
      $xfer += $input->readSetBegin($_etype3, $_size0);
      for ($_i4 = 0; $_i4 < $_size0; ++$_i4)

      { $elem5 = null; $elem5 = new alice(); $xfer += $elem5->read($input); $this->david[$elem5] = true; }

      $xfer += $input->readSetEnd();
      } else

      { $xfer += $input->skip($ftype); }

      break;
      ===

      Using objects as array keys makes PHP cranky and the values can not be properly set. I think the solution to this is either:

      1. Document that the PHP bindings do not support sets of complex types. (boooo!)

      2. Modify the generated code so that the values are stored in array values not keys. (With some additional checks to ensure uniqueness, or perhaps just using spl_object_hash($theObject) as the array key.

      This seems similar to the issues raised in THRIFT-231 and THRIFT-162
      $this->david[$elem5] = true;

      Attachments

        1. thrift-342.patch
          1 kB
          JCF
        2. thrift-342.patch
          0.7 kB
          JCF

        Activity

          People

            bterm JCF
            davidsklar David Sklar
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: