0

I have try to create custom module in magento 2 but i have got error like

Fatal error: Cannot declare class Product, because the name is already in use in /var/www/mymagento/app/code/Plus/Demo/Model/Product.php on line 2

Here is my Product.php

<?php
class Product {     
public function sayHello() {
    echo "hi";
  }
}

And here is my test.php

<?php

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';

$params = $_SERVER;

$bootstrap = Bootstrap::create(BP, $params);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$quote = $obj->get('Plus\Demo\Model\Product');   
//I have created say fucntion under Product.php file
echo '<pre>';
print_r($quote->sayHello());
echo '</pre>'; */

I tried but i still can not success.

Thanks in advance

TRY

1 Answer 1

3

Add namespace in Product.php

app/code/Plus/Demo/Model/Product.php

<?php

namespace Plus\Demo\Model;

class Product
{    
    public function sayHello()
    {
        echo "hi";
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.