Message
Use of undefined constant THIS_SCRIPT - assumed 'THIS_SCRIPT' (this will throw an error in a future version of PHP)
Someone reported this issue with my plugin ( https://github.com/frostschutz/MyBB-Google-SEO/issues/60 ). And here I am, shamelessly trying to offload this issue onto you guys.
Usually THIS_SCRIPT is defined by MyBB at the very top of the file like this:
https://github.com/mybb/mybb/blob/feature/showthread.php#L12
define('THIS_SCRIPT', 'showthread.php');
and then global.php is loaded afterwards
https://github.com/mybb/mybb/blob/feature/showthread.php#L28
require_once "./global.php";
And then various things check THIS_SCRIPT for various reasons. This is a problem if THIS_SCRIPT is undefined, so global.php ALSO defines THIS_SCRIPT:
https://github.com/mybb/mybb/blob/feature/global.php#L32-L35
if(!defined('THIS_SCRIPT'))
{
define('THIS_SCRIPT', '');
}
Now why is that a problem with my plugin? Well, it only happens after the plugin was loaded, because there is all sorts of stuff in global.php before THIS_SCRIPT was redefined to empty string. In particular, init.php is loaded first so THIS_SCRIPT is undefined in init.php and dependencies such as plugins.
https://github.com/mybb/mybb/blob/feature/global.php#L17-18
// Load main MyBB core file which begins all of the magic
require_once $working_dir.'/inc/init.php';
The issue in my plugin would be resolved nicely if MyBB could move the THIS_SCRIPT empty string fallback to the very top of global.php.
Otherwise I'd have to do what the example plugin does....
https://github.com/mybb/mybb/blob/feature/inc/plugins/hello.php#L19
if(defined('THIS_SCRIPT'))
i.e. explicitely check if it's defined first before using it anywhere - but it seems like it should be defined more or less globally (and it's already the case, just not in the early loading phase for plugins) and a lot of other code also simply assumes it's there.
What do you think?
Or perhaps that fallback should be moved to init.php as that is where also other things are defined globally (MYBB_ROOT, TIME_NOW).
There should be no downsides to this change unless there is someone explicitely checking for THIS_SCRIPT nonexistence
if(!defined(THIS_SCRIPT)) { do_something_great(); } /* would no longer work */
but I think it's unlikely for anyone to do that
I’d vote for moving the fallback to init.php personally, given it’s used almost everywhere. I don’t think there would be any adverse affects caused by the change either.
On 4 Feb 2018, at 13:51, Andreas Klauer notifications@github.com wrote:
Or perhaps that fallback should be moved to init.php as that is where also other things are defined globally (MYBB_ROOT, TIME_NOW).
There should be no downsides to this change unless there is someone explicitely checking for THIS_SCRIPT nonexistence
if(!defined(THIS_SCRIPT)) { do_something_great(); } /* would no longer work */
but I think it's unlikely for anyone to do that—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
What about changing it to
if(!defined('THIS_SCRIPT'))
{
define('THIS_SCRIPT', 'unknown');
}
I definitely agree with moving it to init.php. I have multiple plugins that I otherwise have to do additional coding to check for it.
Any progress on that? adding the check&set in init.php helps for to get the forum work without errors, but the admin interface still throws errors.
I've assigned it to 1.8.16, but we don't have a PR yet.
I support what @labrocca suggested, to define fallback value to 'unknown'. If someone explicitely checking for THIS_SCRIPT nonexistence he can just query the value to be 'unknown' or not.
But again if anywhere other place inside MyBB; this kind of explicit check is already in place that should be modified too.