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?

1

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

2 Comments

This needs the runkit extension, which can be installed by PECL.
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.
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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.