Using Sub-namespaces in PHP
📖 Scenario: You are organizing a PHP project for a small library system. To keep the code clean and easy to manage, you want to use sub-namespaces to separate different parts of the system.
🎯 Goal: Create a PHP script that defines a main namespace and a sub-namespace. Then, create a class inside the sub-namespace and use it in the main script.
📋 What You'll Learn
Create a main namespace called
LibraryCreate a sub-namespace inside
Library called BooksDefine a class called
Book inside the Library\Books namespaceCreate an instance of the
Book class and print a message using a method from that class💡 Why This Matters
🌍 Real World
Organizing code in large PHP projects by grouping related classes into sub-namespaces helps keep the code clean and easy to maintain.
💼 Career
Understanding namespaces and sub-namespaces is important for working on professional PHP projects, frameworks, and libraries.
Progress0 / 4 steps