Is it possible to replace (monkeypatch) PHP functions?

前端 未结 6 792
感情败类
感情败类 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 07:57

    I realize this question is a bit old, but Patchwork is a recently-released PHP 5.3 project that supports redefinition of user-defined functions. Though, as the author mentions, you will need to resort to runkit or php-test-helpers to monkey-patch core/library functions.

提交回复
热议问题