views:

30

answers:

0

Scenario:

Two different objects that get their data from a MySQL database (originally, then subsequently from a serialized/unserialized SESSION key) are causing a recursion error for json_encode, but ONLY when another, later INSERT query has failed.

The INSERT query will fail when certain elements are NULL (as mandated by the table structure). The data to be inserted is posted via AJAX and a JSON response is returned.

As it happens, these objects are unnecessary for this request, but I'd like to understand why this is happening. The objects are identical in both scenarios: when the query executes successfully and when it doesn't, right up until the call to the json_encode function. The difference seems to be happening when the json_encode function runs.

For the time being I have simply muted the warning from json_encode:

@json_encode($array_of_obj);

Meaning, in this situation, the objects in JSON are null, as json_encode has failed to serialize them, which is not ideal.