Renaming Functions during runtime in PHP
Asked Answered
M

3

8

In PHP 5.3 is there a way to rename a function or "hook" a function.

There is the rename_function() within "APD" which has been broken since ~2004. If you try and build it on PHP 5.3 you'll get this error:

'struct _zend_compiler_globals' has no member named 'extended_info'

This is a really easy error to fix, just change this line:

GC(extended_info) = 1;

to

CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;

I modified my php.ini and the APD shows up in my phpinfo() as it should. However when i call rename_function() the PHP page doesn't load and I get a segmentation fault in my /var/log/apache2/error.log.

Is there anyway to fix APD to work with a modern version of PHP? Or is there another method to rename functions? Why on earth is vital feature not in php!??!?! (Gotta love python :)

Mordent answered 17/5, 2010 at 2:26 Comment(5)
I know this question is a bit old, but can you show me your code?Flowered
@Flowered as far as I know none of this works any more.Mordent
I got APD to work. So maybe I can help you...Flowered
@Flowered so wait, does rename_function() work on php 5.3.8?Mordent
I think I only tried 5.3.6 (current version in ubuntu afaik)Flowered
I
2

The up-to-date runkit extension can be found on http://github.com/zenovich/runkit It supports all contemporary versions of PHP released for the time being (from 4.4 to 5.4+). This runkit is official and supported.

Sincerely, Dmitry Zenovich

Intrigue answered 8/9, 2012 at 22:1 Comment(1)
Thank you! This is a useful extension.Mordent
Q
2

Runkit trunk is 5.3+ compatible.

svn checkout http://svn.php.net/repository/pecl/runkit/trunk runkit
cd runkit
phpize
./configure
make && make install

Add extension=runkit.so to php.ini (or runkit.ini in conf.d)

In order to use runkit_function_rename() you will also have to recompile php with the --enable-maintainer-zts configuration flag. (Damn you zend!)

Quinate answered 17/5, 2010 at 3:7 Comment(0)
D
2

I realize this question is a bit old, but I was recently looking for a way to rename functions for testing and ran into similar difficulties with APD.

Finally hit on the right Google query and found another option: Sebastian Bergmann's test_helpers extension -- it has its own rename_function() that seems to work just fine, as well as some other handy helpers for intercepting and mocking things.

Bonus - a relatively painless install process:

$ pear channel-discover pear.phpunit.de
$ pecl install phpunit/test_helpers

And then add extension=test_helpers.so to your php.ini

Dapplegray answered 26/5, 2012 at 19:31 Comment(0)
I
2

The up-to-date runkit extension can be found on http://github.com/zenovich/runkit It supports all contemporary versions of PHP released for the time being (from 4.4 to 5.4+). This runkit is official and supported.

Sincerely, Dmitry Zenovich

Intrigue answered 8/9, 2012 at 22:1 Comment(1)
Thank you! This is a useful extension.Mordent

© 2022 - 2024 — McMap. All rights reserved.