⊗ppOpNsSCC 98 of 107 menu

Simplified Access to Namespaces in OOP in PHP

Suppose we have the following class Controller:

<?php namespace Admin; class Controller { } ?>

Suppose there is also a class Page that inherits from the class Controller:

<?php namespace Admin; class Page extends \Admin\Controller { } ?>

As you can see, when inheriting, we specify the parent's name along with the namespace. In this example, however, there is a nuance: both classes belong to the same namespace. In this case, when referring to a class, you can simply write the name of that class, like this:

<?php namespace Admin; class Page extends Controller { } ?>

Given two classes:

<?php namespace Modules\Shop; class Cart { } ?>
<?php namespace Modules\Shop; class UserCart extends \Modules\Shop\Cart { } ?>

Simplify the code for class inheritance, considering that both classes are in the same namespace.

azbydeenesfrkakkptruuz