PHP Basic Tutorial
MySQL Connection
PHP Advanced
A namespace in PHP is a way to organize and group related code (like classes, interfaces, functions, or constants) and prevent name conflicts between parts of your application or with external libraries.
If two classes have the same name (e.g., User
), a namespace separates them.
Helps maintain a clean and modular codebase, especially in large projects or frameworks like Laravel, Symfony, etc.
Namespaces are declared at the beginning of a file using the namespace
keyword:
<?php namespace Html; ?>
Note
The namespace must be declared at the very top of the file.
Constants, classes and functions declared in this file will belong to the Html namespace:
Create a Table class in the Html namespace: