3

Is there a way to reconstruct a php structure from its var_dumped representation? That is, given something like

array(3) {
  [0] =>
  int(1)
  [1] =>
  string(1) "2"
  [2] =>
  array(1) {
    [0] =>
    int(3)
  }
}

obtain array(1, "2", array(3));

If there's no built-in (library) for this, how to write this function?

For simplicity, let's ignore resources and assume all classes defined.

To clarify, I've got a bunch of var_dump'ed data which I need to process. I don't have access to sources.

UPD: As pointed out in the comments, there's a duplicate question, but I'm not happy with the answer posted there. I don't think using regular expressions is the correct approach here, because every "special" character can also occur within a string literal. For example, that code fails to parse string(6) "ab{;cd" or string(8) "float(5)".

Community
  • 1
  • 1
gog
  • 10,367
  • 2
  • 24
  • 38
  • 5
    http://stackoverflow.com/questions/3531857/code-challenge-convert-var-dump-of-array-back-to-array-variable – gherkins May 12 '14 at 08:16
  • Gotcha; I'm going to go ahead and refund your bounty, close this as duplicate, and merge the answer below into that question. If you still want better answers, you can add your bounty to that question instead, since you'll have the points back. That will gain it additional attention. – Andrew Barber May 13 '14 at 14:26

0 Answers0