the mode w+ usually means to erase the contents of a file first, not sure if PHP does anything unusual there. so $dbobj might be empty here. although if it were, what is json_decode doing not to complain that “” is not valid JSON? maybe PHP is a little weird there too.
only changing w+ to r+ shouldn’t do the same thing, but it shouldn’t fully fix it either. with r+, it skips that truncate-to-zero-length step, so you can read successfully. but by then the file is positioned at the end and the fwrite effectively appends. maybe json_decode is being clever and stopping at the end of the first valid json string. you’d end up parsing the contents next time into the same old dictionary as before.