What is the correct way to use this function?
1st:
$limite = \abs($resultado_cadastro->limite);
2º:
$limite = abs($resultado_cadastro->limite);
Both work, but netbeans says that the correct one is \abs
What is the correct way to use this function?
1st:
$limite = \abs($resultado_cadastro->limite);
2º:
$limite = abs($resultado_cadastro->limite);
Both work, but netbeans says that the correct one is \abs
According to the official PHP documentation , both forms are valid.
What happens is that if the function you are using is not found in the current namespace , there will be a fallback to the global namespace .
Tip: You can use first form to discriminate PHP's own function if you write your own version of that function. For example:
function strlen($str)
{
return \strlen($str) - 1;
}
The two forms are correct, however you should use the slash before the name of the function or class when using namespaces this is for all the functions / classes of the core of php, from the compario php will try to find a function called abs()
in the current namespace and since it does not exist it generates an error, as in that question .
Use what is described in the PHP Manual so it will be guaranteed that regardless of machine settings all your code will work correctly. Usually "\" is used when you are making use of a namespace or a class.
Take a look at your friend documentation