MyBB Hacks

Full Version: {Semi-Resolved} MyBB 'Variable Scope' 101
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Variable Scope may not be the exact term, but the idea is similar.

This doesn't work:*

PHP Code:
define("IN_MYBB", 1);
require_once "./global.php";

// include file *after*  define("IN_MYBB...
require_once "./inc/var/example2.php";


*The variables in './inc/var/example2.php', are not set or available.

This works:*

PHP Code:
// include file before  define("IN_MYBB...
require_once "./inc/var/example2.php";

define("IN_MYBB", 1);
require_once "./global.php";


*The variables in './inc/var/example2.php', are set and available to use.

A) None of the variables in 'example2.php' conflict with MyBB standard vars.
B) The 'disappearing vars' are *not* being used inside a function.
C) How come 'they' cannot be included*** after  define("IN_MYBB", 1);  ?

***I'm certain the above is true in at least one case, any idea why?
Thanks for advice.

Most likely because one of your claims is false (my guess is the conflict part; maybe not conflict with variables directly, but sourced inputs are conflicting or similar).

I can't say anything more without a sample.
Would $global_var1 (for example) cause a conflict since it uses $global before the '_' ? (I had assumed "No" since $global != $global_... )
No that should work fine.
With your help, I figured it out now.   Smile

(09-20-2010 03:39 PM)ZiNgA BuRgA Wrote: [ -> ]... but sourced inputs are conflicting or similar)...

Of course you are correct, and now I know why:
My original example was over-simplified, I should have mentioned the tasks folder

PHP Code:
// include file located in 'tasks' folder does NOT work (for defining some variables), after define("IN_MYBB...
require_once "./inc/tasks/example2.php";


PHP Code:
// Using the same include file placed in 'myvars' folder *does* work
require_once "./inc/myvars/example2.php";

  • So globals.php, or a related file, 'scans' every file in ./inc/tasks folder, even if the 'task' is not active.
^^^
The above statement must be true, or there is a HUGE hole in my logic.
Thanks again Zinga.
It shouldn't, if it's a standard MyBB task file, since all they contain is a function.  They don't even do a IN_MYBB check.
(09-20-2010 07:18 PM)ZiNgA BuRgA Wrote: [ -> ]It shouldn't, if it's a standard MyBB task file, since all they contain is a function.  They don't even do a IN_MYBB check.

A file with just a few vars is "acting differently" when placed in ./inc/tasks/ vs.
./inc/myvars/
^^^
Not sure exactly why; Thanks for the helpful tips Zinga.
There are many possible reasons, but MyBB is unlikely to be one of them.

Why can't you post the file?
(09-21-2010 08:25 AM)ZiNgA BuRgA Wrote: [ -> ]There are many possible reasons, but MyBB is unlikely to be one of them.

Why can't you post the file?

I usually avoid posting exact domain names (which some of the 'vars' are using), since I'm working on launching a bunch of unique sites all at one time.

PHP Code:
<?php

$local_hub = "example_hub1.com";
$major_hub = "major_hub1.com";
$global_hub = "abc123.com";
$npoints = "234000";
$syncpath = "rsync -av /var/www/html/mysource/ /var/www/html/example_domain.com";

?>


The vars are so basic, I'm surprised they work the one way and not the other; Makes no sense, really...

Works perfectly fine here.

PHP Code:
<?php
define("IN_MYBB", 1);
require_once "./global.php";

// include file *after*  define("IN_MYBB...
require_once "./vars.php";

var_dump($local_hub, $major_hub, $global_hub, $npoints, $syncpath);

http://mybbhacks.zingaburga.com/example.php

Pages: 1 2
Reference URL's