Reputation: 91
In Symfony, some functions have a root namespace and some functiona do not, why?
For example:
// code from symfony
if (file_exists($cache->getPath()) && \is_object($this->container = include $cache->getPath())) {
$this->container->set('kernel', $this);
$oldContainer = $this->container;
$fresh = true;
}
file_exists
does not have a namespace, but \is_object
does.
I've noticed that this sort of difference occurs throughout the whole Symfony project.
Upvotes: 4
Views: 349
Reputation: 688
This could most likely be to get the performance improvements that were introduced to some functions in PHP 7.0 where some functions where replaced by opcodes. In order to get these improvements these functions have to be referenced to by the root namespace.
This issue on the PHP-CS-Fixer GitHub repository includes a comment with a list of functions that use this. file_exists
has not been improved in this manner so it will yield no performance improvement to reference it by the root namespace. This issue was also referenced many times by PRs for the Symfony GitHub repository.
Here is a link to the PHP source code where you can also find the list of functions with this behaviour.
Upvotes: 2