MySql - bigints, php and auto string / int casting flip-flopping

Yesterday I asked a question about mining, to which I was kindly answered. However, I am observing some strange behavior and would like to understand what is happening.

In my php, I have an array that I send back to the javascript web client program that uses it.

In php

    sendBack = null;
    sendBack[0]['TimeStamp'] = $Time; // A bigint got from a mysql table milliseconds from 1970
    sendBack[0]['Text'] = $Message; // A varchar message got back from mysql
    // I am guessing at this point you have worked out this is a text-chatroom thing going on
    sendBack[1]['TimeStamp'] = 0; // A zero indicates an admin issue - note its an int but a small one
    sendBack[1]['Text'] = $MessageAdmin;

    // And I pack it up to send back
    echo json_encode($sendBack);

In js, I will unpack it for use with:

    var json = eval('(' + data + ')');

The problem is that the TimeStamp time index in js is processed as a string, but the index 1 index index is processed as int.

From an educational point of view, does anyone know what is going on?

0
source share
1 answer

, , PHP, . , - :

sendBack[0]['TimeStamp'] = parseInt($Time, 10);

(base-10).

, 1 , , int.

+1

All Articles