Notice: Unknown: Skipping numeric key 1 in Unknown on line 0


I have the following code:

include 'includes/connect.php';
$sp= "clot";
$selectall = mysqli_prepare($connection, "SELECT Count FROM prices WHERE Category = ? ORDER BY ppu LIMIT 11");
mysqli_stmt_bind_param($selectall, 's', $sp);
$resulttotal = mysqli_stmt_get_result($selectall);
while($row = mysqli_fetch_array($resulttotal, MYSQLI_ASSOC)){
$_SESSION[$x] = $row['Count'];
        $_SESSION['nextstart'] = $_SESSION[$y];

Which outputs the expected string of numbers (1, 17, 2, 18…) this error message(ten times, with key 1, key 2, key 3, and so on):

Notice: Unknown: Skipping numeric key 1 in Unknown on line 0

Looking this error up, the only answer I could find was that putting an array into a superglobal would cause this. I don’t believe I’ve put an array in, $row['Count'] is a string, isn’t it? I couldn’t find any entries on stackoverflow about this error.

What causes this error, and what should I do to fix it? (The shown code is just me experimenting and planning a design for endless pagination using my database.)


The PHP session storage mechanism was originally built around "registering" variables, so the keys in $_SESSION must be names that could be treated as variables in their own right.

This means that $_SESSION[42] is invalid, because $42 wouldn’t be a valid variable name, and since $foo[42] and $foo['42'] refer to the same thing, $_SESSION['42'] is invalid as well.

The solution is either to use a prefix on your session variables (e.g. $_SESSION['row_count_' . $x] = $row['Count'];) or make them into an array, which you can then loop over etc later (e.g. $_SESSION['row_counts'] = array(); ... $_SESSION['row_counts'][$x] = $row['Count'];)

Note: this limitation is actually part of the "serialization handler" used when writing the session to disk, which is why the errors have no context (they’re fired while PHP is shutting down). In current versions of PHP there is a setting of session.serialize_handler which doesn’t have this limitation:

php_serialize is available from PHP 5.5.4. php_serialize uses plain serialize/unserialize function internally and does not have limitations that php and php_binary have. Older serialize handlers cannot store numeric index nor string index contains special characters (| and !) in $_SESSION. Use php_serialize to avoid numeric index or special character errors at script shutdown.

Answered By – IMSoP

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published