Namespace declaration syntax
📖 Scenario: Imagine you are organizing your PHP code into different sections to keep it neat and avoid name clashes. Namespaces help you do this by grouping related code together.
🎯 Goal: You will create a PHP file that declares a namespace and defines a simple function inside it. Then you will access that function using the namespace.
📋 What You'll Learn
Declare a namespace called
MyApp\UtilsCreate a function called
greet inside the namespace that returns the string 'Hello from Utils!'Call the
greet function using the full namespace pathPrint the result of the function call
💡 Why This Matters
🌍 Real World
Namespaces help large PHP projects stay organized by grouping related code and avoiding name conflicts.
💼 Career
Understanding namespaces is important for working on professional PHP applications and frameworks that use modular code.
Progress0 / 4 steps