Hi, I've made a pull request where I was asked to start internal discussion about it.. The pull request can be found: https://github.com/php/php-src/pull/1884 Which relates to request I've also made: https://bugs.php.net/bug.php?id=72073
For short the thing is: "We have objects that do dynamic loading and there might be recursions. We could use recursion depth to decide when we want to do dynamic loading and when not. Now there doesn't seem to be any way to know how deep is the json_encode process going. If we try to use some level in jsonSerialize it just calls one of those, no recursion there. This could be easily archived by exposing the internal encoder_depth to jsonSerialize." As I don't know any other way to get the depth info from jsonSerialize, as it isn't called recursively in PHP side, so adding some static class variable and incrementing/decrementing it in jsonSerialize will just not work. Then to why would someone really need that? Well, we have models that uses MongoDB as a database (created from MongoDB objects) and the models can have references to other models (coming from MongoDB objects). That loading will happen dynamically and there might be recursions, but we want still to serialize them as we really don't need to go that deep even if there is a recursion. This way we can control the depth we are loading new objects and can avoid recursion happening in jsonSerialize and can get the data we need serialized. If you are thinking why don't you just use the depth option of json_encode, well unfortunately it doesn't help. It seems to go too deep and get recursion errors and would just later limit the depth it's going as my example will show if you try if you run it without patched json. Any comments/ideas? -- Jani Ollikainen -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php