php - Variable showing as undefined straight after it's been initialized -
maybe i'm tired programming, tell me why prints user doesn't exist?
// create user class hold session data $user = new stdclass(); function init () { if (!isset($user)) echo 'user doesn\'t exist'; } init();
you have issue variable scope, variable cannot accessed function init, try using global key word // create user class hold session data $user = new stdclass();
function init () { global $user; if (!isset($user)) echo 'user doesn\'t exist'; } init();
Comments
Post a Comment