0





59
1

I have created a module in Joomla and all is working fine, but when I put a function in and try and access a variable it does not work, but if I echo it outside the function it is ok

$item_img = $params->get('item_img','modules/mod_k2_mobile/images/item_icon.gif');

// not working
function GetIMG(){
    global $item_img;
    echo "item".$item_img;
}
GetIMG();

// working
echo "item".$item_img;

why?

Question author Gringoloco007 | Source

0


1

I would advice you not to use any global variables as long as you can avoid it. Can't you change your function declaration to something like "GetIMG( $item_img )"? If you still want to use a global variable, this should work:

**global $item_img;**

$item_img = $params->get('item_img','modules/mod_k2_mobile/images/item_icon.gif');

// not working
function GetIMG(){
    global $item_img;
    echo "item".$item_img;
}
GetIMG();

// working
echo "item".$item_img;

I hope it helps!

Answer author Alghimo

Ask about this question here!