MyBB Community Forums
[PHP] Can't able to get uid with $mybb - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Community Archive (https://community.mybb.com/forum-106.html)
+--- Forum: Archived Forums (https://community.mybb.com/forum-143.html)
+---- Forum: Archived Development and Support (https://community.mybb.com/forum-155.html)
+----- Forum: MyBB 1.6 (https://community.mybb.com/forum-138.html)
+------ Forum: 1.6 General Support (https://community.mybb.com/forum-127.html)
+------ Thread: [PHP] Can't able to get uid with $mybb (/thread-129628.html)



[PHP] Can't able to get uid with $mybb - sunjava1 - 2012-11-18

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();

?>



RE: [PHP] Can't able to get uid with $mybb - crazy4cs - 2012-11-18

Try to define global $mybb inside the function.

Also, it's

$mybb->user['uid']

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


RE: [PHP] Can't able to get uid with $mybb - sunjava1 - 2012-11-18

(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 ?


RE: [PHP] Can't able to get uid with $mybb - crazy4cs - 2012-11-18

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.


RE: [PHP] Can't able to get uid with $mybb - sunjava1 - 2012-11-18

oahky Smile