Zend certified PHP/Magento developer

Load Magento objectmanager via a class

Having a bit of an issue with this one, I managed to get a working interface to Magento by including the following code, which in turn includes the Magento 2 bootstrap.php

use MagentoFrameworkAppBootstrap;
require_once("../app/bootstrap.php");
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('adminhtml');
return $obj;

which returns an object that has the callable Magento methods. I’ve been trying to convert this into a callable class, so that I can call new magento() and have the same functionality, but in more compact code.

use MagentoFrameworkAppBootstrap;
require_once("../app/bootstrap.php");

class magento extends Bootstrap {

    public $params;
    private $bootstrap;
    public $obj;
    private $state;

    public function  __construct() {
        $this->params = $_SERVER;
        $this->bootstrap = Bootstrap::create(BP, $this->params);
        $this->obj = $this->bootstrap->getObjectManager();
        $this->state = $this->obj->get('MagentoFrameworkAppState');
        $this->state->setAreaCode('adminhtml');
        return $this->obj;
    }
}

However, when running this class, the subsquent code

$product = $obj->get('MagentoCatalogModelProductRepository')->getById( $entity_id );

the get function is being called from the magento class, not the $object

Fatal error: Uncaught Error: Call to undefined method magento::get()

I think I’m missing something obvious, but can’t quite get my head around it.