I’ve got a PHP class which extends ArrayIterator, and has all the necessary methods implemented so that it behaves like an array.
This works fine for things like foreach loops, but calling print_r on it still prints out the object’s variables, rather than printing it as it would an array.
Is there some way of overriding this behaviour so that calling print_r (and I guess var_dump) will print custom output for this object?
No, because it is designed to give information about the variable (i.e. it is used for debugging) and not just to give some string representation of it.
You can overwrite
__toStringthough and useecho.