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

Extending Thrift class results in "Attempt serialize from non-Thrift object"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.10.0
    • 0.12.0
    • PHP - Library
    • None
    • Linux 4.13.3-1-ARCH
      PHP 7.1.10

    • Patch Available
    • Patch

    Description

      This happens when using php extension. thrift_protocol_write_binary will check Z_TYPE_P of spec and expects to be array (IS_ARRAY). However, PHP7 will set it as reference (IS_REFERENCE).

      Example:

      $s = new Serializer\TBinarySerializer();
      
      // Foo is a Thrift type class
      class FooExtended extends Foo {}
      
      $o = new Foo();
      $o2 = new FooExtended();
      
      // this works just fine:
      $s->serialize($o); // this uses thrift_protocol_write_binary if available
      
      // Next line throws \Thrift\Exception\TProtocolException if thrift_protocol_write_binary is used
      // However, it doesn't break if no extension is available.
      $s->serialize($o);
      

      Proposed solution is to dereference using ZVAL_DEREF before checking types (attached). Alternative would be to mark struct type classes as final, but that break compatibility.

      Attachments

        Activity

          People

            jking3 James E. King III
            sokac Josip Sokcevic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: