MyBB Community Forums

Full Version: [PHP] Can't able to get uid with $mybb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Why I can't get $mybb variable in function ?
<?
define("IN_MYBB", 1);
require "../global.php";

global $mybb;
function getid()
{
$userid=$mybb->user[uid];
return $userid;
}

echo getid();

?>
Try to define global $mybb inside the function.

Also, it's

$mybb->user['uid']

and not $mybb->user[uid] (you missed single quotes).
(2012-11-18, 06:46 PM)crazy4cs Wrote: [ -> ]Try to define global $mybb inside the function.

Also, it's

$mybb->user['uid']

and not $mybb->user[uid] (you missed single quotes).

It works but why the Global works if we define it out side of our every function ?
You're requiring global.php already, which has mybb defined (it requests from inc/init.php where $mybb variable's formation starts) hence it works.

But when function comes, it does not use the file (here, global.php as it's outside the function) and hence we have to define $mybb in globals for it to get work there.
oahky Smile