alias a function

alias a function

am 27.10.2004 04:27:32 von Justin French

Hi,

What's the quickest way to alias a user function?

I have a function which uses english spelling (eg categorise instead of
categorize), and I want to alias the function with an "Americanized"
spelling.

I'd rather that the alias categorize() did not have to be altered in
any way to "keep up" with changes to the parent function categorise()
-- in particular, having the correct number of attributes and default
values, for example.

TIA
Justin French

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: alias a function

am 27.10.2004 05:46:47 von Curt Zirzow

* Thus wrote Justin French:
> Hi,
>
> What's the quickest way to alias a user function?
>
> I have a function which uses english spelling (eg categorise instead of
> categorize), and I want to alias the function with an "Americanized"
> spelling.
>
> I'd rather that the alias categorize() did not have to be altered in
> any way to "keep up" with changes to the parent function categorise()
> -- in particular, having the correct number of attributes and default
> values, for example.

Instead of aliasing, I would deprecate the function, so the old
function would be:

function categorise($arg1, $arg2) {
trigger_error('Deprecated categorise used', E_USER_NOTICE);
return categorize($arg1, $arg2);
}

As far eliminating the parameter changes, I can only think that
you'd need to use func_get_args() and call_user_func_array():

function categorise() {
call_user_func_array('categorize', func_get_args());
}

The latter solution is quite a bit of overhead just to get an alias,
perhaps trigger_error with that method as you migrate old code.



Curt
--
Quoth the Raven, "Nevermore."

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: alias a function

am 27.10.2004 13:49:21 von Justin French

On 27/10/2004, at 1:46 PM, Curt Zirzow wrote:

> Instead of aliasing, I would deprecate the function, so the old
> function would be:

really hoping to alias rather than deprecate, but since it's not too
easy, I'll just ditch the idea I think :)

Thanks,
Justin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php