dsztc99732 2017-03-25 20:25
浏览 212

通过表单GET传递0及其null,但intval(0)为0

HTML:

echo "<form action='procSS.php' method='get'>
";
echo "<button style='color:black;' type='submit' name='start' value='" . $data[0]\ . "'> start </button>";

echo "<button style='color:black;' type='submit' name='stop' value='" . $data[0] . \"'> stop </button>";
echo "</form>";

procSS.php

<?php

$server_conn = stream_socket_client("tcp://127.0.0.1:9000", $errno, $errmsg);

echo intval(0);

if($_GET['start'] == null || $_GET['stop'] == null) {
    echo "its null my dude";
}
if(!empty($_GET['start'])) {
    fwrite($server_conn, "Start ".$_GET['start']."");
    echo "Start ".$GET_['start'];
    fclose($server_conn);
} elseif(!empty($_GET['stop'])) {
    fwrite($server_conn, "Stop ".$_GET['stop']."");
    echo "Stop ".$_GET['stop'];
    fclose($server_conn);
}  elseif(!empty($_GET['reset'])) {
    fwrite($server_conn, "Restart ".$_GET['reset']."");
    fclose($server_conn);
} else {
    echo "???";
}

?>

Okay so this is the url -> http://localhost/procSS.php?stop=0 and it clearly sends 0. the output on the php page is: 0its null my dude???. So I did intval(0) which it returns 0. Next we see that $_GET['stop'] is null even though it passes 0. Why is this and how can I fix it? intval(0) is 0, but passing 0 through get is null

  • 写回答

1条回答 默认 最新

  • 普通网友 2017-03-25 20:28
    关注

    because it both are false 0 is false as well as null is also false when used for condition

    use strict type checking(===) like this 0 === null

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)