Are class declarations in PHP always global, or are there exceptions?

Class declarations in PHP are not always global. They can be contained within namespaces to avoid conflicts with other classes of the same name. By using namespaces, you can organize your code more effectively and prevent naming collisions. To define a class within a namespace, you simply include the namespace declaration before the class definition.

namespace MyNamespace;

class MyClass {
    // class code here
}