Integration issue
So, I'm trying to build a site, and integrate some MyBB functions into it. However, I'm running into a weird issue.

What I want to do is create an extension for this new site build which pulls in MyBB support. This extension is in a separate directory.
1) If I pull in global.php in this extension directory, I get errors which don't seem to make sense.
2) If I pull in global.php in the root folder, it seems to work fine.
3) If I start declaring global variables which I know MyBB to use, THEN pull in global.php in the extension directory, I start getting different errors, and eventually, things start to work. However, this isn't viable, as I'd need to anticipate every single global variable MyBB and its third-party extensions use.

I'm guessing this is some simple issue I'm overlooking like a dumb, but does anyone have any insight on this?
I have a site which use MyBB, essentially for user login and post parsing.
What I did:
define('IN_SIT', true);
defined('IN_MYBB') or define('IN_MYBB', 1);
define('FORUM_PATH', realpath(BASE_PATH.'/../forum/'));
require_once FORUM_PATH.'/global.php';
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
I gave that a try; however, I'm getting the same issue. It doesn't work unless I start manually defining globals.

Dunno if it would help to show the directory structure:

  core.php <- includes /private/Extensions/MyBB.php
   MyBB.php <- includes /html/forum/global.php
  index.php <- includes /private/core.php

I'm also using namespaces in the site code, but my understanding is that any include statements inside a namespace will run the included source file in the global namespace unless it explicitly defines a different one. I tried:

- Splitting MyBB.php into two namespace sections; the first part in global, and the second part where it's meant to be, and including global.php in the global portion (this didn't work)
- Having MyBB.php include another file running exclusively in the global namespace, which would include global.php (this didn't work either)
- Just for science, putting index.php into a namespace and including global.php from there (this DID work, but creates an explicit MyBB requirement for my site software, which I want to avoid)

So, as far as I can tell, whether or not there is a namespace doesn't matter, but any source file in private which tries to pull in the forum software results in failure due to the global variables not loading in correctly.
Okay, I think I figured it out. The globals were being stored in the context of the autoload function which was pulling in the forum extension. Calling require on the extension, rather than letting it be loaded in by the autoload function, seems to result in success. However, it seems in poor form to manually check for and pull in an extension when there's an autoload function there, meant to do so dynamically as needed. Does anyone have any suggestion on a solution for this that doesn't require a hack?

Forum Jump:

Users browsing this thread: 1 Guest(s)