douke8473 2012-07-11 12:43
浏览 13
已采纳

PHP中的预增量和后增量

the result of the following statement should give 9 : (using java or js or c++)

i = 1;
i += ++i + i++ + ++i;
//i = 9 now

but in php

the same statements will give 12 ?!

$i = 1;
$i +=  ++$i + $i++ + ++$i;
echo $i;

is this a bug or can anyone explain why ?

  • 写回答

5条回答 默认 最新

  • dongpaocuan7498 2012-07-11 12:48
    关注

    The answer is "because it's PHP". And PHP doesn't make guarantees about that type of statement (incidentally, neither does C).

    Yes, it could be considered wrong, but it's PHP. See this "not a bug" bug report.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案