Can I use private instance methods as callbacks?

后端 未结 3 528
逝去的感伤
逝去的感伤 2021-01-17 11:18

My particular scenario involves doing some text transformation using regular expressions within a private method. The private method calls preg_replace_callback, but is seem

3条回答
  •  忘掉有多难
    2021-01-17 11:30

    Can you create a separate helper class for text processing, and create the callback method within that class (it can be public there)? You can pass in a reference to the original class(object) if you need access to specific instance data.

    The public interface to your main class remains consistent and clean, and you pull specific string processing out of a class it probably doesn't belong in anyway...

提交回复
热议问题