Uploaded image for project: 'Couchbase PHP client library'
  1. Couchbase PHP client library
  2. PCBC-759

Decoder always returns JSON objects as arrays, not stdClass as expected

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.1.2
    • 3.1.1
    • library
    • None
    • Windows 10, Apache, PHP 7.4
    • 1

    Description

      BOTH JSON objects AND JSON arrays are decoded by the SDK 3.1 into PHP arrays when fetching/decoding documents. For example, for this document:

      "address": {
       "address1": null,
       "city": null,
       "county": null,
       "state": null,
       "zip": null
       },

      I expect address to be fetched/decoded into a PHP stdClass instance, but instead, it is incorrectly decoded into a PHP array:

      [address] => Array <-- wrong, should be stdClass
       (
       [address1] => 
       [city] => 
       [county] => 
       [state] => FL
       [zip] => 
       )

      This makes the SDK effectively useless, as it's critically important that I distinguish between objects and arrays in returned results.

      Documentation loosely mentions a php.ini configuration setting:

      couchbase.decoder.json_arrays = 0

      But this setting has no effect.  It appears to be completely ignored by the SDK. It also appears to default to true instead of false.

      We're instructed to set the value to false to decode JSON objects into stdClass instances, but if I use false instead of 0, the setting isn't even read by php.ini. When using 0, the setting is read by php.ini, but still completely ignored.

      Until this issue is resolved, I'll be forced to roll back to PHP SDK v2.x. This is unfortunate, because v3 introduced a host of breaking changes that required rewriting a bunch of middleware in my app.

      Help!

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            avsej Sergey Avseyev
            rmirabelle Robert Mirabelle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty