Funny php bug due to hashing and is_numeric

So I was working on an automation project and was testing the api to upload entitites.

I used get parameters to send data and wrote a wrapper on server to process that. I used hashes (part of hashes to be precise) to identify the requester instead of using real names.

some name came up with hash


I was using first 10 characters of this has which happen to be


If you notice, only alphabet is “e” and all others are digits.
But at the same time this is a number in scientific notation
just the way 1e3 is 1000 because of exponentiation involved. My partial hash string was also being converted and was close to infinity.

My api at the backend was checking the given parameter with is_numeric and in this case, my parameter “12200e7973is 100% numeric (EVEN IF I WAS STORING IT AS A STRING).
Hence my script was failing to save correct data and a major column was left empty in the tables.

This was another blunder by me at programming, but you can easily fix it if you use is_int instead of is_numeric because it would fail type checking via is_int.

Of course I had to edit some code with explicit type casting for other types of api calls which were using IDs instead of hashes to identify the users.

Example code: (This is Not the exact code, not recommended for production usage)

$user=isset($_REQUEST['user']) ?? $_REQUEST['user'] : 1;
// calling the function with string $user
abc ("xyz",$user);
// Normal code:
$userid=(int)$user; //explicit casting
//calling the same function with int val

How to reverse the ids in a mysql table column without breaking primary key constraint?

Let me explain the problem scenario: Let us assume we have a table with 4 columns in it out of which 1 is PRIMARY column and rest 3 contain some data.

What we want to do is to reverse the primary key IDs for that data keeping the rest of data intact. It is like shifting the first row to end and moving last row to starting.

Initial Data

1jacobwhateverhow to reverse
3nathanwhosoeverisnathanids in mysql table column
4jagmohanidontknowjagmohanwithout breaking
8monicaiamsexyprimary key constraint
9batmanidontexistinrealworldi am batman

Data after update

9jacobwhatever how to reverse
8nathanwhosoeverisnathan ids in mysql table column
4jagmohanidontknowjagmohan without breaking
3monicaiamsexy primary key constraint
1batman idontexistinrealworld i am batman

Dude, you are just reversing the column, what is so tough in this?

So, this seems simple to reverse an array if isolated by key “id“. But you have to understand that this column is the primary key. So if you run a command to change id for “jacob” to “9“. It will give you error: “Duplicate entry for id 9

So here is my proposed solution, I start with pair of first and last row and then swap them. Then swap second and second last row. and So on…

If total rows are odd, we will be left with 1 row which does not need correction because it will already be the middle row.

If total rows are even, we would swap middle two rows too.

Here is my solution in PHP

$ai=12720; //can be any high int which does not exist in column `id` yet
$q="select id,email from table_name where `possible_group_id`=$possible_group_id order by id asc";
echo "start transaction;<br>";
foreach($row_collection as $k=>$v)
    if($k < floor($size/2)){
    echo 'UPDATE `table_name` SET `id`='.$ai.' WHERE `email`="'.$row_collection[$size-$k-1][1].'";<br>';
    echo 'UPDATE `table_name` SET `id`='.$v[2].' WHERE `email`="'.$v[1].'";<br>';
    echo 'UPDATE `table_name` SET `id`='.$row_collection[$k][0].' WHERE `email`="'.$row_collection[$size-$k-1][1].'";<br>';}
    else break;
echo "commit;<br>";

It would output this:

start transaction;
UPDATE `table_name` SET `id`=12720 WHERE `email`="idontexistinrealworld ";
UPDATE `table_name` SET `id`=9 WHERE `email`="whatever";
UPDATE `table_name` SET `id`=1 WHERE `email`="idontexistinrealworld ";
UPDATE `table_name` SET `id`=12720 WHERE `email`="iamsexy";
UPDATE `table_name` SET `id`=8 WHERE `email`="whosoeverisnathan";
UPDATE `table_name` SET `id`=3 WHERE `email`="iamsexy";