In Magento 2 we have to create a lot of data for ourselves using helper-modules. In the Vendor/Example/Helper/Data.php
I often see either of these two at the top of the file:
use Magento\Framework\App\Helper\AbstractHelper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
And sometimes both:
use Magento\Framework\App\Helper\AbstractHelper;
class Data extends AbstractHelper
And I'm wondering, is there any difference to either use
or extend
the AbstractHelper? Is there a right or wrong?
A simple answer I found is this:
You can use multiple traits, you can't extend multiple classes.
Does this translate into you either extend
to add new stuff to it, and use
it to get existing data? And again, is there an upside or downside in using either in Magento?
use
keyword just allows you to reference that class without supplying the full namespace, thereby improving the readability of code. It's purely aesthetic.