2

I would like to overwrite a couple of functions that are already declared in PHP. The application I am working with is full of legacy code (including calls to eval()) so just replacing the identifier where the functions are called in the code might not be enough.

Is it possible to change a function that has already been declared, without using the Advanced PHP Debugger in PHP5?

Tom
  • 6,991
  • 13
  • 60
  • 78
  • possible duplicate of [Is it possible to replace (monkeypatch) PHP functions?](http://stackoverflow.com/questions/530649/is-it-possible-to-replace-monkeypatch-php-functions) – Gordon Jun 23 '10 at 10:00

2 Answers2

3

Yes, by using

It's a PECL extension and can be installed via PEAR. But keep in mind that redeclaring functions does not substitute for proper refactoring. You are just exchanging one evil for another.

Also see Is it possible to replace (monkeypatch) PHP functions?

Community
  • 1
  • 1
Gordon
  • 312,688
  • 75
  • 539
  • 559
  • This needs the runkit extension, which can be installed by PECL. – Emil Vikström Jun 23 '10 at 09:55
  • This is just a temporary preventive measure. I will not refactor this hazard disguised as PHP code, but I will rewrite it completely page-by-page. – Tom Jun 23 '10 at 10:19
0

Usual question - Why? What do you expect to achieve?

including calls to eval()

Are you suggesting that you might write your own eval() function? Good luck! Or do you just want to disable certain functionality? If its the latter, then how do you know that your dummy replacement is not going to cause functional issues? And if you only want to disable speficic functions, then you can do that from the php.ini file.

OTOH, if it were me and I had working wrapper/replacement functions, I'd just use find and sed to rewrite the files then add an auto-prepend include file which included the relevant function definitions. (actually, I have done exactly that in the past).

HTH

C.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • I have a function, let's say `strtoupper` that is called from the PHP scripts sometimes as a function and sometimes using `eval()`, so I can't really sniff out all the sources of the calls (some function calls come from the database and some are made by concatenating strings to generate the function name). Yes, it is THAT bad. – Tom Jun 24 '10 at 10:36