What are some common pitfalls when using namespaces in PHP, especially when trying to access objects in different folders?
One common pitfall when using namespaces in PHP, especially when trying to access objects in different folders, is not properly importing the namespaces of the classes you want to use. To solve this issue, make sure to use the correct namespace when referencing the class, and use the `use` keyword to import the namespace at the top of your file.
// File: folder1/ClassA.php
namespace Folder1;
class ClassA {
// Class implementation
}
```
```php
// File: folder2/ClassB.php
namespace Folder2;
class ClassB {
// Class implementation
}
```
```php
// File: index.php
require_once 'folder1/ClassA.php';
require_once 'folder2/ClassB.php';
use Folder1\ClassA;
use Folder2\ClassB;
$objA = new ClassA();
$objB = new ClassB();