Is it possible to replace (monkeypatch) PHP functions?

前端 未结 6 804
感情败类
感情败类 2020-11-27 07:36

You can do this in Python, but is it possible in PHP?

>>> def a(): print 1
... 
>>> def a(): print 2
... 
>>> a()
2
6条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 08:19

    The accepted answer is excellent!!! I will just add,that you can put your codes in Namespace brackets and then the default GLOBAL-SPACE is resetted.

    some other ways:

    1) rename_function($old_name,$new_name)

    2) override_function($old_name, $parameters, $new_func)

    and rarely used:

    3) runkit_function_rename(...)

    4) runkit_function_redefine(...)

提交回复
热议问题