1
irmtfan
global variables: $GLOBALS["module"] vs $GLOBALS["xoopsModule"] vs $GLOBALS["xoops"]->module
  • 2012/11/7 9:24

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


We have different methods for defining global variables.
specifically, I have issue with xoopsModule global variable in xoops < 2.6
in xoops 2.5.5 in some core/modules we have $GLOBALS["xoopsModule"]
but in a few of them (eg in XOOPSCORE/search.php) we just have $GLOBALS["module"] so for example i have to write this code to have consistency :
// irmtfan - if XOOPSCORE/search.php then $xoopsModule is not set
    
if ( !is_object($GLOBALS["xoopsModule"]) && is_object($GLOBALS["module"]) && $GLOBALS["module"]->getVar("dirname") == "newbb" ) {
        
$GLOBALS["xoopsModule"] = $GLOBALS["module"];
    }


in xoops 2.6 core team remove all global variables and use one $xoops global variable for this purpose so we can have this:
$module_dir $GLOBALS["xoops"]->module->getVar('dirname''n');


so i need to know what should i do to make sure that there is not error when $xoopsModule is not set but $module is set.

2
zyspec
Re: global variables: $GLOBALS["module"] vs $GLOBALS["xoopsModule"] vs $GLOBALS["xoops"]->module
  • 2012/11/7 15:34

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


irmtfan,

Can you tell me where you see $GLOBALS["module"]? I looked in XOOPSCORE/search.php in both 2.5.4 and 2.5.5 and do not see it referenced anywhere.

3
irmtfan
Re: global variables: $GLOBALS["module"] vs $GLOBALS["xoopsModule"] vs $GLOBALS["xoops"]->module
  • 2012/11/8 4:43

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


sorry i should explain more.
$GLOBALS["xoopsModule"] is defined like this after including kernel/module.php file:
$module_handler =& xoops_gethandler'module' ) ;
$xoopsModule =& $module_handler->getByDirname$mydirname ) ;

in other words $xoopsModule is a global object variable defined in kernel/module.php
So it is up to core developers how to name it.
they generally name it $xoopsModule but somehow they name it $module in XOOPSCORE255/search.php
see lines 134-168:
$module_handler =& xoops_gethandler('module');
        
$criteria = new CriteriaCompo(new Criteria('hassearch'1));
        
$criteria->add(new Criteria('isactive'1));
        
$criteria->add(new Criteria('mid'"(" implode(','$available_modules) . ")"'IN'));
        
$modules $module_handler->getObjects($criteriatrue);
        
$mids = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array();
        if (empty(
$mids) || ! is_array($mids)) {
            unset(
$mids);
            
$mids array_keys($modules);
        }
        
$xoopsOption['xoops_pagetitle'] = _SR_SEARCHRESULTS ': ' implode(' '$queries);
        include 
$GLOBALS['xoops']->path('header.php');
        
$nomatch true;
        echo 
"

_SR_SEARCHRESULTS "

n"
;
        echo 
_SR_KEYWORDS ':';
        if (
$andor != 'exact') {
            foreach (
$queries as $q) {
                echo 
htmlspecialchars(stripslashes($q)) . ''
;
            }
            if (!empty(
$ignored_queries)) {
                echo 
'';
                
printf(_SR_IGNOREDWORDS$xoopsConfigSearch['keyword_min']);
                foreach (
$ignored_queries as $q) {
                    echo 
htmlspecialchars(stripslashes($q)) . '';
                }
            }
        } else {
            echo 
' "htmlspecialchars(stripslashes($queries[0])) . '"';
        }
        echo 
'';
        foreach (
$mids as $mid) {
            
$mid intval($mid);
            if (
in_array($mid$available_modules)) {
                
$module $modules[$mid];
                
$results $module->search($queries$andor50);


these lines are important:
$module_handler =& xoops_gethandler('module');
.....
        
$modules $module_handler->getObjects($criteriatrue);
.....
....
                
$module $modules[$mid];


But in most modules module developers will use $GLOBALS["xoopsModule"]

I wonder why no module developer encounter this issue before.
It seems no developer needed $GLOBALS["xoopsModule"] in his search function.
but i need it in newbb.
i dont have issue inside module in modules/newbb/search.php
but i should correct it for XOOPSCORE/search.php
so i did these changes yesterday and now it is work fine:
http://sourceforge.net/p/xoops/svn/10246/

4
zyspec
Re: global variables: $GLOBALS["module"] vs $GLOBALS["xoopsModule"] vs $GLOBALS["xoops"]->module
  • 2012/11/8 13:58

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Now I understand. I personally haven't counted on $GLOBALS['xoopsModule'] in module search functions since previous versions of XOOPS have been inconsistent. I usually get a 'local' copy of the module handler just to be sure I know what's going on. Probably not the most efficient (time or memory) but I know it works.

5
irmtfan
Re: global variables: $GLOBALS["module"] vs $GLOBALS["xoopsModule"] vs $GLOBALS["xoops"]->module
  • 2012/11/10 5:53

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


All globals should be accessible in all functions so i call it a core bug.
And yes maybe using a copy of module handler will be more reliable for all versions.
But newbb 4.3 is just for xoops 2.5.x (2.5.5 is recommended) so it is a good solution.
for xoops 2.6 all modules should be rewrite because all globals will be changed by $xoops even you cannot use xoops_gethandler( 'module' ) and should use $xoops->getHandlerModule()

Login

Who's Online

347 user(s) are online (238 user(s) are browsing Support Forums)


Members: 0


Guests: 347


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits