Re: Functions/methods aliases in PHp 5.2

From: Date: Sun, 15 May 2011 21:48:30 +0000
Subject: Re: Functions/methods aliases in PHp 5.2
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-312791@lists.php.net to get a copy of this message
On 15 May 2011 21:45, Andre Polykanine <andre@oire.org> wrote: > Hi everyone, > > Is there any possibility to make a method or function alias in PHP? > Yes, I know I can do the following: > > <?php > function foo_bar($x) { > // And so we code... > return $result; > } > > function FooBar($x) { > return foo_bar($x) > } > > But maybe there is a more elegant solution? > Thanks! Whilst you can do class_alias() - something I use to hide the long class name for soap services - there isn't a function alias. But, if you are creating your own functions, then you could use a closure and that can be assigned to a variable ... $fn_FooBar = function() { ... }; $fn_FooBar($a, $b, $c); or someFunc($fn_FooBar) { ... } Closures are ideal for callbacks. Why do you want to alias functions? Is it to obscure the existing name? If so, take a look at using an encoder. This uses the compiled code rather than the source to run. It is faster to run as there is no compile phase and the "code" isn't very easy to reverse. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.general (#312791) next »