preg_replace_callback() - Callback inside current object instance

前端 未结 3 977
夕颜
夕颜 2020-12-11 14:06

Warning: preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, \'info\', to be a valid callback in [...]

public function getDisplay(         


        
3条回答
  •  眼角桃花
    2020-12-11 14:29

    Instead of using anonymous functions or more complex methods, you can just use one of methods supported for passing callbacks (see the documentation on callbacks):

    A method of an instantiated object is passed as an array containing an object at index 0 and the method name at index 1.

    To pass "info" method of current object as a callback, just do the following:

    array($this, 'info')
    

    and pass it wherever you want to use "info" method as a callback within one of the objects other methods.

提交回复
热议问题