Can this really be PHP?

I’ve just spent well over an hour (could easily be over two hours - I loose count) trying to work out why my session management stuff for somenew work is failing.

See if you can spot the problem with this pseudo code:

// on one page I store an object into session memory
$_SESSION['oStaff'] = serialize($oStaff);

// then on another page I try to get it back
function foo()
{
   if(!$oStaff = unserialize( $_SESSION['oStaff'] ))
   {
      return False;
   }
   return True;
}

This was always returning False. Can you see what is causing the problem?

No? Well, from what I can tell, it looks like PHP (my version, at least) doesn’t like the use of mixed case letters in session variable names! Bah! I’ve been trying to get this to work for ages, and I’ve got a headache now.

So when I replaced it with the following (renaming my session variable), everything seemed to start working:

// on one page I store an object into session memory
$_SESSION['ostaff'] = serialize($ostaff);

// then on page another I try to get it back
function foo()
{
   if(!$oStaff = unserialize( $_SESSION['ostaff'] ))
   {
      return False;
   }
   return True;
}

I was hoping to get my new Editor’s Console up and ready for the people that have offered to help with BritBlog by now. It’s mainly working now except for the authentication framework, which was what this is all for. It’s going to be a good few days before I get any more time to spend on this now :-(

Sociable:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg
  • Furl
  • NewsVine
  • Reddit
  • YahooMyWeb

One Response to “Can this really be PHP?

  • JBlanch
    June 8th, 2005 03:06
    1

    try if($oStaff != unserialize( $_SESSION[’ostaff’] ))

    and make sure $ostaff is global with
    global $oStaff at the top of function foo()

Leave a Reply