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

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

And here is my test.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');

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

I tried but i still can not success.

Thanks in advance



Add namespace in Product.php



namespace Plus\Demo\Model;

class Product
    public function sayHello()
        echo "hi";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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