du16178 2015-10-23 20:46
浏览 443

PHP将所有数组值转换为字符串

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?

  • 写回答

2条回答 默认 最新

  • dongshi1606 2015-10-23 21:48
    关注

    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}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?