You can use functions from different namespaces. But you have to be aware of how to bring in that function. Remember, the function has a fully qualified name which includes its namespace. When using that function in another namespace, you have choices:
- You can specify its fully qualified name such as
- If the namespace is the root, then you can use a relative name such as
- You can alias the namespace and then use that alias in place of the fully qualified namespace
- If you are using PHP 5.6 and up, then you can import the function.
You can learn more about aliasing and importing in the PHP manual.
Your best friend is code, Tonya is making the introductions.
Total Lab Runtime: 02:25:26
- 1 Lab Introductionfree 02:59
- 2 What and Why of Namespacingfree 20:15
- 3 Why Namespacing instead of Prefixing?free 12:39
- 4 The Basicspro 17:36
- 5 Fully Qualified Namingpro 06:50
- 6 Callbacks and Namespacingpro 08:00
- 7 Name Resolution Rulespro 12:17
- 8 Using Functions from Another Namespacepro 16:37
- 10 Class Basicspro 12:20
- 11 Practical Example: Convert from Prefixingpro 10:08
- 12 Real World Example: Convert from Prefixingpro 06:14
- 13 Architecture - Building in Packages and Modulespro 08:59
- 14 PHP Examples - Laravel & Symfonypro 02:50
- 15 Wrap it Upfree 07:42