here is my problem. I am trying to create one big file (full of functions) which will call the object functions. I want to create some SUPERGLOBAL variable which will contains everything about that called class (even between functions) class like "user". What data? Just something like user's ID, Name, Email, Level from database so I don't need to using SQL SELECT from USERS in almost every function in this file.
This is how my core.php file looks like (it's cut just to explain what am I trying to do)
//File -- core.php
require_once "pdo.php"; //Includes the $db -- pdo connection to database
require_once "user.php"; //Including the object
$GLOBAL["user"] = new USER($db);
function login($email, $pswd){
$GLOBAL["user"]->login($email, $pswd); //LOGIN and also in this class function are written the data like $GLOBAL["user"]->ID, etc
//do something more
}
function ShowLoggedUser(){
echo $GLOBAL["user"]->ID; //But now here it's not working -> it's empty, nothing there
echo $GLOBAL["user"]->Email;
//etc
}
And the thing is, that's I in the object USER I am setting the public data like
//file -- user.php
class USER
{
//Public data
public $Name;
public $Level;
public $ID;
public $Email;
private $DB;
function __construct($DB_con)
{
$this->DB = $DB_con;
}
public function login ($email, $password)
{
//Some SQL and verifying user with DB
//if everything is ok do this:
foreach($result as $data){ //Results from SQL -- details about user
$this->ID = $data["ID"];
$this->Name = $data["Name"];
$this->Email = $data["Email"];
}
return "some message";
}
The function Login is the key of this file, if the login won't be used, then the user is kicked out of this file (it's file just for logged users), so there is 100% guaranty that's the data in class are written and they really shows up when I echo them in the function "login". But anywhere else it's just totally empty...
Thank you for any help / tips!