Jump to content

[SOLVED] large key


php_joe

Recommended Posts

I have a variable with a very large key and it gets parsed in a strange way.

 

Here is the code:

<?
$line[11988600574445] = "line one";
foreach($line as $key => $msg) echo "$key|$msg<br>\n";
?>

 

and it outputs:

-2147483648|line one

 

If I have:

<?
$line[11988600574445] = "line one";
$line[11988600942070] = "line two";
$line[1198860109608] = "line three";
foreach($line as $key => $msg) echo "$key|$msg<br>\n";
?>

 

I end up with just one line on the page:

-2147483648|line three

 

Which, as you can see, is the last value in the array and that's not the right key.

 

What's going on?

Link to comment
Share on other sites

The numeric index values exceed what can be represented in an integer. PHP is likely generating an error on the first two lines (check your web server log for errors.) The third one is small enough a value that it is within the +/- range of a signed integer and looks like a negative value because the MSB is set.

 

Use quited strings as indexes to fix your problems.

 

As to why the first single example outputs something? It's anyone's guess. Probably has something to do with the error response code in php or the code you posted is not exactly the code that generated the output.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.