Newbie question - $result->value still serialized


#1

Brand new install from source, both of couchbase and the PHP connector. Connecting OK using hello world code, but the $result->value field is still a serialized JSON string, so the subsequent lines don’t work as written in the example. I know I’m missing something obvious, but dang if I can figure out what.

For kicks I tried $myBucket->setTranscoder('json_encode', 'json_decode'); but that generated a different error (depth must be greater than 0).

For completeness, here’s the actual returned object. I expected $result->value to be a stdObj, rather than a string:

CouchbaseMetaDoc Object
(
    [error] => 
    [value] => {"name":"Juleøl","abv":5.9,"ibu":0.0,"srm":0.0,"upc":0,"type":"beer","brewery_id":"aass_brewery","updated":"2010-07-22 20:00:20","description":"The Norwegian Juleøl can be traced back more that 1000 years. The \"Gulatinglov\", one of the first Norwegian laws written in the 9th century, has a chapter on brewing beer for the midwinter celebration in January. The festivities were held to celebrate the Norse Gods; Odin, Frøy and Njord as well as the \"return\" of the sun.\r\nFurthermore, the tradition was adopted by the Vikings that brought Christianity to the country between 1000 and 1100. They moved the tradition to December in connection with the birth of Jesus. \r\nIn those days a farmer that did not set aside the best crop to produce the beer could lose his house to the king and the church. The law has been changed, but we promise you that we still use the very best of malt, yeast, hops, and pure Norwegian water to produce our Christmas beer.\r\n\r\nAass Juleøl has won most of the Norwegian Juleøl taste test conducted over time. For those of you that know what \"lutefisk\" is, Aass Juleøl is the perfect choice of beverage to this traditional Norwegian dish.","style":"Dark American-Belgo-Style Ale","category":"North American Ale"}
    [flags] => 0
    [cas] => Resource id #3
)

Update to add:

insterted the following:

$myBucket->setTranscoder(
    function($object) {
	print "encoding :\n";
	var_dump($object);
	print "\n\n".json_encode($object);
	return json_encode($object);
    },
    function($string) {
	return json_decode($string);
});

And got the expected object on get(). However, replace() returned an object with a null value and the document in the database was emptied as well. The outputs in the transcode function give every appearance that it is returning a reasonable value for the serialized string.

System info: MacOS X 10.10.4; php 5.6; php sdk version 2.0.7; couchbase: 3.1.0


#2

Are you wanting to know what to expect as far as response type on each request? Or are you wanting to set what the response type will be each time?


#3

The behavior I see does not match the documentation; the very simple example code does not work because the default transcoding of the data from the server is not happening. I should see a PHP object, but I’m just getting a string.

When I try to supply my own transcoder it decodes properly, but on encoding I get unexpected behavior that leads to data loss, even though the string returned by the transcoder function seems to be correct. So, at this point I’m unable to use this SDK.