I see that in Python, we can import only one function from a given module, without having to load it all. In addition, this is great for avoiding role name conflicts.
Example:
#funcs.py
def x(x):
return 'x'
def y(y):
return 'y'
#main.py
from funcs import y
print(y()); #y
print(x()); #erro é gerado
However, in PHP, when we have the same scenario, we have:
#func.php
function x($x)
{
return 'x';
}
function y($y)
{
return 'y';
}
#main.php
include_once 'funcs.php';
echo y(); // y
echo x(); // x
Even though there are no native methods of importing just one function in PHP, is there any solution to this?
Or, should I always use the default below when I'm going to use functions in php?
if (! function_exists('y')) {
function y($y){ return 'y'; }
}