convert recursive_unserialize_replace() function to a class

benefits:

- avoids exposing intermediate recursion variables, such as
  $recursion_level
- clearer which elements are constant and which change

see #951