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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -