1

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.

Mike Everhart
  • 408
  • 3
  • 10

1 Answers1

1

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

Pierre
  • 1,553
  • 12
  • 22
  • OHHH! That makes sense, and I can totally see that in the code now that you pointed it out. Thank you very much for the quick and comprehensive reply! As soon as I'm able I will accept your answer. – Mike Everhart Nov 13 '15 at 21:21