|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-02-16 07:04 UTC] guillaume at lya dot fr
Description:
------------
I'm trying to replace a native function by my own function and to make a call to the native function into it.
Reproduce code:
---------------
I'm trying to rename a native function to insert my own code like this :
[code]
<?
function new_strlen($str) {
print "new strlen !";
return old_strlen($str);
}
runkit_function_rename('strlen', 'old_strlen');
runkit_function_rename('new_strlen', 'strlen');
strlen("toto");
?>
[/code]
But this doesn't works, there is different bugs results if you reload the page, like this example :
[quote]
new strlen !
Fatal error: Non-static method (null)::t���|���|�������������������������������������������������������������������,() cannot be called statically in /var/www/virtual/suggestion.dev.box/htdocs/suggestion/test3.php on line 4
[/quote]
To prevent this bug, I have adapted the source to copy the original "strlen" to "old_strlen", and to delete the existing function "strlen" before renaming my own "new_strlen" to "strlen" :
[code]
<?
function new_strlen($str) {
print "new strlen !";
return old_strlen($str);
}
runkit_function_copy('strlen', 'old_strlen');
runkit_function_remove('strlen');
runkit_function_rename('new_strlen', 'strlen');
strlen("toto");
?>
[/code]
Like this, I can reload the pages X times, all working fine.
But... if I just add include('PEAR.php'), I have sometimes this error :
[quote]
Fatal error: Cannot redeclare _pear_call_destructors() (previously declared in /usr/share/php/PEAR.php:0) in /usr/share/php/PEAR.php on line 790
[/quote]
Expected result:
----------------
Function replaced by my own function who call the native function whithout any bugs.
Actual result:
--------------
Stranges bugs returns
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 01:00:01 2025 UTC |
Try this hack: runkit_function_copy('strlen','old_strlen'); runkit_function_redefine('strlen','$str','print "new strlen !";return old_strlen($str);');