"Warning: Illegal offset type" problem

0 Benny Lindwall · July 4, 2015
I get the following error messages when trying out Alex's oop login/register video tutorial.

All the code he has done up to the end of the login video has worked perfectly without any deviation from his results.

The first error I get is from the login.php file after entering a correct username, password and hitting the submit button.

( [] = input fields )

Warning: Illegal offset type in C:\xampp5.6.8\htdocs\ooplr2\classes\Session.php on line 8

And from the index.php where he did the temporary check to show that you were actually logged in by displaying the id I got
Warning: Illegal offset type in C:\xampp5.6.8\htdocs\ooplr2\classes\Session.php on line 12

I did some searching on google and all I got was that it was an "string abuse that was not given an error in php 5.3.x and earlier versions".

Is there something wrong in the code he did or did I do something wrong, I check, rechecked, rechecked the rechecked and rechecked all the rechecks on the Session class code, and can't find anything wrong with it. ?_?


Post a Reply


Oldest  Newest  Rating
0 Ron Butcher · July 5, 2015
Can you re-post your Session.php file?  It is not showing up.  

Usually Illegal Offset means that you are trying to access an array key using an object or another array instead of a string or number.
0 Benny Lindwall · July 5, 2015
Here ya go, looks like the code entering isn't always working....


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];

    public static function delete($name) {
        if(self::exists($name)) {

    public static function flash($name, $string = '') {
        if(self::exists($name)) {
            $session = self::get($name);
            return $session;
        } else {
            self::put($name, $string);
+1 Ron Butcher · July 10, 2015
You need to find out what the $name variable is.  In your Session.php file, temporarily change the function put() to the following:

public static function put($name, $value)
echo $name;

return $_SESSION[$name] = $value;

This will echo the $name variable and then kill the page.  If it displays anything other than the name you were expecting, you need to start going back in your code to where you assign the $name variable that you pass in.
0 Benny Lindwall · July 12, 2015
Thanks Ron!

The problem was in the init.php file, instead of 'session_name' I had accidently wrote 'seesion_name'.

That's the problem of typing faster then your mind and eyes can keep up with ;p

Thanks again!
  • 1



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