Often I'll be going through tutorials written by various people, and see underscores used for private or protected vars/properties within a class.
e.g., one person will will have:
protected $_storeManager;
public function __construct(
\Magento\Store\Model\StoreManagerInterface $_storeManager
)
{
$this->_storeManager = $_storeManager;
}
and another tutorial will have:
protected $_storeManager;
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
) {
parent::__construct($context);
$this->_storeManager = $storeManager;
}
And yet another will have
protected $storeManager;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
) {
parent::__construct($context);
$this->storeManager = $storeManager;
}
Is there any rhyme or reason for this? Is there a reason you would ever use a _ for a protected or private class property? Magento docs say they follow PSR-2 standards, which states
"Property names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility."