Getting error on adding an attribute programmatically in Magento 2

A Khan
A Khan used Ask the Experts™
I am trying to add an attribute programmatically in Magento 2 but getting error. Please I need urgent help.
Thanks in advance. Details are as below:

I followed the instructions on and tried to add attribute.
I have windows 7,xampp with php 7.0, magento 2.1 and mysql.
in path variable I set following for php commands:

When I run
C:\xampp\htdocs\maglocal1>php bin/magento setup:upgrade
I get following error at the end

Parse error: syntax error, unexpected 'use' (T_USE) in C:\xampp\htdocs\maglocal1
\app\code\Atwix\TestAttribute\Setup\InstallData.php on line 5

My data in \app\code\Atwix\TestAttribute\Setup\InstallData.php is

namespace Atwix\TestAttribute\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
 * @codeCoverageIgnore
class InstallData implements InstallDataInterface
     * EAV setup factory
     * @var EavSetupFactory
    private $eavSetupFactory;
     * Init
     * @param EavSetupFactory $eavSetupFactory
    public function __construct(EavSetupFactory $eavSetupFactory)
        $this->eavSetupFactory = $eavSetupFactory;
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
         * Add attributes to the eav/attribute
                'type' => 'int',
                'backend' => '',
                'frontend' => '',
                'label' => 'Test Attribute',
                'input' => '',
                'class' => '',
                'source' => '',
                'global' => \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => false,
                'default' => 0,
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => true,
                'unique' => false,
                'apply_to' => ''
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I solved the issue. I tested on new installation and got new error.
That is solved by replacing \Magento\Catalog\Model\Model\Eav\Attribute with \Magento\Catalog\Model\ResourceModel\Eav\Attribute


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial