My particular scenario involves doing some text transformation using regular expressions within a private method. The private method calls preg_replace_callback, but is seems that callbacks need to be public on objects, so I'm stuck breaking out of the private world and exposing implementation details when I'd rather not.
So, in a nutshell: Can I use an instance method as a callback without losing encapsulation?
Thanks.
Best Solution
Yes, it seems you can:
So it seems that
preg_replace_callback()
, or PHP's callback mechanism, is aware of the scope in which it was called.Tested on 5.2.8