php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56842 runkit_function_rename doesn't works
Submitted: 2006-02-16 07:04 UTC Modified: 2013-02-23 14:24 UTC
From: guillaume at lya dot fr Assigned: pollita (profile)
Status: Closed Package: runkit (PECL)
PHP Version: 5.0.5 OS: Linux Ubuntu Breezy
Private report: No CVE-ID: None
 [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&#65533;&#65533;&#65533;|&#65533;&#65533;&#65533;|&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;,() 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-05 09:30 UTC] burik666 at gmail dot com
Try this hack:

runkit_function_copy('strlen','old_strlen');
runkit_function_redefine('strlen','$str','print "new strlen !";return old_strlen($str);');
 [2013-02-23 14:24 UTC] pollita@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pollita
 [2013-02-23 14:24 UTC] pollita@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 10 13:01:26 2024 UTC