Zend - The PHP Company




Miscellaneous

Add Code


func_alias  

Type: code fragment
Added by: pnoq
Entered: 07/06/2002
Last modified: 06/12/2001
Rating: - (fewer than 3 votes)
Views: 3683
This function allows you to create an alias for a function. For example if you do not like the function name 'substr', create your own alias named 'mid' (perhaps you know this function name from BASIC). It does not work with function which use references.


<?php

function func_alias($original_func_name$alias_name)
{
    eval(
'

        function '
.$alias_name.'()
        {
            $args = func_get_args();
            $eval_string = "$return = '
.$original_func_name.'(";
            $i = 0;
            foreach ($args as $k=>$v) {
                $i++;
                $eval_string .= "&$args[$k]";
                if ($i < count($args)) {
                    $eval_string .= ", ";
                }
            }
            $eval_string .= ");";
            eval($eval_string);
            return $return;
        }
    '
);

    return 
true;
}

?>


Usage Example


<?php
func_alias
('substr''mid');
echo 
mid('test'12);
?>


Rate This Script





Search



This Category All Categories