3
I own a set of functions using a third-party API. From time to time I thought of making it available, since there is no library publishes in PHP and it makes no difference to keep as a closed source or not. (I’ll still have to change a lot of things.)
However, as I only use such functions, they have strange names and do not match the actual result, and have no prefix. To solve this I thought of simply renaming the functions and include a prefix.
This way all functions would change to:
MinhaApi_*
However, it would be too long to write, so I thought I’d shorten it to:
ma_*
Hence the curiosity:
It is possible to have MinhaApi_*
and ma_*
simultaneously, without declaring them twice?
So you can understand, instead of using this:
function MinhaApi_text(){
return 'Isso é um texto';
}
function ma_text(){
return MinhaApi_text();
}
echo ma_text();
Resultado: Isso é um texto
This works, but requires you to "re-declare" all functions (so I believe it is not the best way).
Wear this:
function MinhaApi_text(), ma_text(){
return 'Isso é um texto';
}
echo ma_text();
Resultado "esperado": Isso é um texto
That nay works, logically!
If I understand correctly gives yes p to give an alias p function, entering you need to use namespaces and in the call(
use
) give the desired name.– rray
@rray, for functions also gives? I thought it was only for
classes
– Miguel
Yes, now if it’s practical in your case, I don’t know. Taken from documentation: "PHP Namespaces provide a way in which to group Related classes, interfaces, functions and constants"
– rray