Illegal Offset type

0 Kumi Festus · March 10, 2015
I have the code below, anytime I run I get this error 'Illegal Offset On line 10', Someone helped that I omitted a semi-colon and used so many brackets. Actually I didn't make those typos in my original code. I made them when writing the code on this platform. I have copied the entire code and pasted here as I have originally written it. I am happy for suggestions.

class Session{
     public static function exists($name){
        return (isset($_SESSION[$name]))?true:false;
     }
     public static function put($name,$value){
        return $_SESSION[$name] = $value;
     }
     public static function get($name){
        return $_SESSION[$name]; //Illegal offset on this line
     }
     public static function delete($name){
        if(self::exists($name)){
            unset($_SESSION[$name]);
        }
     }
     public static function flash($name,$string = null){
         if(self::exists($name)){
             $session = self::get($name);
             self::delete($name);
             return $session;
         }else{
             self::put($name,$string);
         }
        
     }
 }
?>


Post a Reply

Replies

Oldest  Newest  Rating
0 Mohamad Mirohamadi · March 13, 2015
the code is correct maybe there is a problem in get function argument by the way replace get function with this:
public static function get($name, $default=null){
return (self::exists($name) ? $_SESSION[$name] : $default);
}
0 Kumi Festus · March 16, 2015
Thanks a lot, the offset issue has disappeared.
I will continue with the next level
  • 1

PHP

107,272 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators