dongli9894 2016-07-21 02:11
浏览 6
已采纳

C和PHP之间if('0')的内在差异?

Will someone explain the inner difference of if('0') between C and PHP? In C, if('0') gets false, while in PHP gets true.

  • 写回答

1条回答 默认 最新

  • dongmeng1868 2016-07-21 03:51
    关注

    Well, the "C" language, which dates from the 1970's, is a good bit more literal than PHP! :-)

    First of all, the "C" language really has no concept at all of "a string data type." "None of that had been invented yet."

    Furthermore, the compiler "presumed that you actually knew what you were doing." (That is to say, "that you would not feed it 'nonsense.'") Being a very literal language, it presumed that you must be thinking the same way.

    Fast-forward at least one human generation, and we come to "PHP." CPU's are now vastly more-powerful than a PDP-7 ever was, and memory is an order-of-magnitude bigger, and by now we're trying to "bend the language's interpretation of things, to better match "ordinary human" meanings, instead of the other way around.

    Thus, the PHP language sees "0" as "false-y." Instead of restricting its point-of-view to "a particular storage representation," as C is designed(!) to do, PHP sees "0" as being "zero" ... even though, strictly-speaking, it is "a string" ... and thus sees it as: "false-y."

    Yeah ... "potential interpretations of the meaning of source-code" have indeed "changed in forty-plus(!) years ..."

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀