-1

I have a problem with arrays.

On an old server all the data in arrays were with good types: a string was a string, a bool was a bool and an int was an int.

Now after a server change, all array values are "casting" to string. I cannot compare them with === against my integers because they are "string"

This is how it looks with laravel dd on the old server, versus the new one.

Is there any php setting that causes this that should be fixed?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
rafwlaz
  • 484
  • 2
  • 17
  • 2
    please post code NOT screen shots –  Oct 23 '15 at 20:50
  • 1
    It may be something related to how you're interacting with the database(PDO?), see http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo – james Oct 23 '15 at 21:14
  • What's the difference between the old and the new server? – Evert Oct 23 '15 at 21:23
  • @NathanielFord why not? Now I "fix" it with changing === with ==. This is not question about using === but found the reason of my problem. – rafwlaz Oct 24 '15 at 09:46
  • @Dagon I'm using Laravel, the same script, the same db stucture just moved to new server. – rafwlaz Oct 24 '15 at 09:47

2 Answers2

0

Looking at the screenshots it looks like the following is happening.

  • null value is changed to empty string
  • integer values are now strings

Database

  • Check the column types in the database are these still int and not varchar ?
  • Since PHP 5.3.3 there is a json_encode param called JSON_NUMERIC_CHECK is this used ?

Maybe some framework is updated and using json_encode/json_decode with/without this param. This will result in integer values as strings.

echo json_encode(array('event_id' => '603'));
echo json_encode(array('event_id' => '603'), JSON_NUMERIC_CHECK);

//and the output:

{"event_id":"603"}
{"event_id":603}
khoekman
  • 1,153
  • 7
  • 16
  • the colums are the same, I'm using laravel. And just move script to another server, db structure is 100% the same, the code is 100% the same, the diff is server. – rafwlaz Oct 24 '15 at 09:45
0

On laravel, you could just cast the string to become integer. For example:

return (int)$your_variable->your_column
buczek
  • 2,011
  • 7
  • 29
  • 40
nipek
  • 810
  • 1
  • 9
  • 22