newbtophp Posted March 23, 2010 Share Posted March 23, 2010 I'd like to make more reliable way of replacing function names (currently im using str_replace), theirfore I thought I could make a user defined function which is used exactly the same way as str_replace however it's dependency is token_get_all. (so it manipulates token_get_all to find a function [internal & userdefined] like the $search and replace all occurences of it) So for example: <?php function replace_function($search, $replace, $code){ $tokens = token_get_all($code); //proceed with complex code... } $code = '<?php deval("hey"); ?>'; $code = replace_function('deval', 'echo', $code); echo $code; ?> All help is appreciated. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/196291-help-on-usage/ Share on other sites More sharing options...
ignace Posted March 23, 2010 Share Posted March 23, 2010 For portability reasons it is highly discouraged to replace functions with your own baked (untested) functions instead try namespacing your own functions like my_* or something Quote Link to comment https://forums.phpfreaks.com/topic/196291-help-on-usage/#findComment-1030775 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 Yes, As you'll see in any professional code samples (IE very large CMSs, Boards), They use their own namespaces or function prefexes. (Sometimes only but an underscore ("_") is needed before the function name if you're not sure what functions may be intercepted by your naming convention). Quote Link to comment https://forums.phpfreaks.com/topic/196291-help-on-usage/#findComment-1030781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.