1

As it turns out I will be having to call get_defined_vars() quite a lot in different classes and files. I don't like the particular looks of this function name, so I want to rename it to something simpler like variables() or vars().

I've done some reading and I learned that I can "import" it with an alias within a namespace.

use function \get_defined_vars as variables;

But that means I will have to be aliasing in every file for this to work. I was wondering - is there any way I could alias the function globally so it would be callable from anywhere with this alias?

  • Have you checked this? http://stackoverflow.com/questions/1688711/can-we-alias-a-function-in-php?rq=1 – rlanvin Aug 27 '15 at 20:19
  • @rlanvin yes, it is not very helpful. I can't create a wrapper function because `get_defined_vars` uses the context it is called in, unless I can somehow make a function that has access to the variables in the scope it is called which I think is not possible, or? – Emilio Rodrigues Aug 27 '15 at 20:57
  • 1
    I think you're right, and even if there was a way it would probably be a big hack. So no obvious way to make a wrapper, and I'm afraid there is no solution for making "global" `use` statements as far as I know. Well, from the look of it, I'd say there is no solution. But let's see, maybe somebody else comes up with a genius idea. – rlanvin Aug 27 '15 at 21:28

0 Answers0