Problem with query from PHP script

You should not invoke encoder, you have to specify reference to the encoder implementation. try

$couchBucket->setTranscoder("couchbase_default_encoder", function($bytes, $flags, $datatype) {
    if ($flags == 0) {
        $flags = COUCHBASE_CFFMT_JSON;
    } //$flags == 0
    return couchbase_default_decoder($bytes, $flags, $datatype);
});

To verify, you have to upsert/get the value

<?php
$cluster = new CouchbaseCluster("couchbase://localhost");
$bucket = $cluster->openBucket("default");


$COUCHBASE_DEFAULT_DECOPTS = array(
    'jsonassoc' => true
);
$bucket->setTranscoder(

  // encoder($value) -> array($bytes, $flags, $datatype)
  "couchbase_default_encoder",

  // decoder($bytes, $flags, $datatype) -> $value
  function ($bytes, $flags, $datatype) {
    if ($flags == 0) {
       $flags = COUCHBASE_CFFMT_JSON;
    }
    return couchbase_default_decoder($bytes, $flags, $datatype);
  }

);

var_dump($bucket->upsert("foo_json_flags", array("foo" => array("nested" => "bar"))));
var_dump($bucket->get("foo_json_flags"));
object(CouchbaseMetaDoc)#5 (5) {
  ["error"]=>
  NULL
  ["value"]=>
  NULL
  ["flags"]=>
  NULL
  ["cas"]=>
  string(9) "scj1gu8es"
  ["token"]=>
  NULL
}
object(CouchbaseMetaDoc)#5 (5) {
  ["error"]=>
  NULL
  ["value"]=>
  array(1) {
    ["foo"]=>
    array(1) {
      ["nested"]=>
      string(3) "bar"
    }
  }
  ["flags"]=>
  int(33554438)
  ["cas"]=>
  string(9) "scj1gu8es"
  ["token"]=>
  NULL
}

Try :

return \couchbase_default_decoder($bytes, $flags, $datatype);

I wonder if it is enough something like

$bucket->setTranscoder(\couchbase_default_encoder, ...

If EdanBrooke is in a namespace he sould put \ before couchbase_default_encoder and couchbase_default_decoder

I assumed he is verifying on some minimal examples with CLI, but okay. Any way to provide implementation would work, but not invocation of actual encoder.