Just checked, native json_encode does some special handling:
- First execute jsonSerialize.
-- If return value equals $this then use "old" json_encode.
-- If return value equals another object then recurse (and thus recheck jsonSerialize).

Possible solution:
1. Check jsonSerialize result. If not equal to $this, use recursion (safest and most predictable).
2. If result is equal to $this, continue execution (we will remove the "else" from line 262).

This will not prevent a loop, if 2 objects are referring to eachother, however this is not a new "bug" since nameValue already recurses.
A solution to memory exhaustion in this case would be a depth parameter just like native json_encode.

Let me know if you agree and I'll implement the solution. Note that this infinite recursion would also occur in a normal object if i set $this->someProperty = $this as far as I can tell...