Php use a class in the constructor of another class and require it with namespace

I have som legacy code that broke after an update of a dependency class of my ex colleague’s Handler class of the Cosenary Instagram Class using composer.

The former reference to include the class in the handler class was this:

namespace AcmeInstagram;
class Handler
{ 

/* GOT SOME USEFUL VARS HERE */

const API_URL = 'https://api.instagram.com/v1';

/**
 * Initialize the library
 *
 * @param array  $settings Contains our ClientId and upload dir
 * @param string $root_dir The root of our application
 */
public function __construct( $settings, $root_dir = __DIR__ )
{
    include_once  $root_dir . '/vendor/cosenary/instagram/instagram.class.php'; //HERE WAS THE INCLUDE BEFORE


    // THROW SOME EXCEPTIONS HERE IF SETTINGS MISSING ETC...

    // New instance of the instagram class
    $this->_instagram = new Instagram($this->_clientId);
}

/* HANDLE SOM FUNCTIONS HERE */

}

And if I change the include_once to:

    require_once $root_dir . '/vendor/cosenary/instagram/src/Instagram.php';

Then I get:

Fatal error: Class 'AcmeInstagramInstagram' not found in

I guess I need to pass it in as a reference in the constructor but that means I need to rewrite a lot of code and there is probably 5-10 other projects that is depending on this Hanlder class. Is there a way to use the instagram class in this other class?

Tried moving out the include_once and:

use MetzWebInstagramInstagram;

But no luck, any help or pointers i greatly appreciated.


Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.