I'm working with Sage from roots.io and noticed that they are "including" functions (not files), like:
<?php include Namespace\Function(); ?>
I really like this approach, but I've been all through the PHP docs, and my Google-fu is failing me here...
I'd like to know if this is officially supported by PHP (ie: is it undocumented and likely to be unsupported in the future?)
I'd also like to know if there are any implications or "gotchas" with doing it this way instead of just importing the namespace and calling the function, or instantiating a class and calling a method.
It's not including functions, but rather including a file that the function returns.
So Namespace\Function()
returns a path to a file that is then included using include
.
Since PHP 5.6, you can import an already loaded function from a namespace using the use function
syntax. Please have a look at the documentation for more info: http://php.net/manual/en/language.namespaces.importing.php