当Echo不存在时,PHP服务器错误500?

时间:2015-12-19 17:17:32

标签: php echo

当我在某个地方添加回声时,我的PHP代码工作正常,但当我删除简单的echo "hello";行时,它不会加载php页面,它只显示服务器错误500.

以下代码有效:

require 'steam.php';
    $steam = new steam();
    $api = "FC1D74A835829EB99A571235A499638A";
    $query = 'ari9';

    $communityID            =   $steam->getID($query, $api);
    $userInfo               =   $steam->getUserInfo($communityID, $api);

    echo "hello";

    $info = array(
        'communityID'   =>  $communityID,
        'steamID'       =>  $steam->$convertToSteamID($communityID),
        'personaname'   =>  $userInfo['personaname'],
        'profileurl'    =>  $userInfo['profileurl'],
        'lastlogoff'    =>  $userInfo['lastlogoff'],
    );

    foreach ($info as $key => $value) {
        if (strlen($value)===0) {
            $info[$key] = false;
        }
        echo $key." -> ".$value."<br>";
    }
    echo json_encode($info);

以下代码工作:

require 'steam.php';
    $steam = new steam();
    $api = "FC1D74A835829EB99A571235A499638A";
    $query = 'ari9';

    $communityID            =   $steam->getID($query, $api);
    $userInfo               =   $steam->getUserInfo($communityID, $api);

    $info = array(
        'communityID'   =>  $communityID,
        'steamID'       =>  $steam->$convertToSteamID($communityID),
        'personaname'   =>  $userInfo['personaname'],
        'profileurl'    =>  $userInfo['profileurl'],
        'lastlogoff'    =>  $userInfo['lastlogoff'],
    );

    foreach ($info as $key => $value) {
        if (strlen($value)===0) {
            $info[$key] = false;
        }
        echo $key." -> ".$value."<br>";
    }
    echo json_encode($info);

以下代码工作:

require 'steam.php';
    $steam = new steam();
    $api = "FC1D74A835829EB99A571235A499638A";
    $query = 'ari9';

    $communityID            =   $steam->getID($query, $api);
    $userInfo               =   $steam->getUserInfo($communityID, $api);

    $info = array(
        'communityID'   =>  $communityID,
        'steamID'       =>  $steam->$convertToSteamID($communityID),
        'personaname'   =>  $userInfo['personaname'],
        'profileurl'    =>  $userInfo['profileurl'],
        'lastlogoff'    =>  $userInfo['lastlogoff'],
    );

    foreach ($info as $key => $value) {
        if (strlen($value)===0) {
            $info[$key] = false;
        }
        echo $key." -> ".$value."<br>";
    }
    echo json_encode($info);

    echo "Hello";

第一段代码在第9行有回声,第二段与第一行相同,只是删除了第9行的回声。我很困惑。

1 个答案:

答案 0 :(得分:2)

问题是这个$steam->$convertToSteamID正在寻找一个具有变量值的名称的函数。在没有回声的情况下获得500的原因是因为当您发送服务于200的回声时。日志中应该有事件显示错误。您不能在页面上拥有2个状态代码。

所以只需将您的函数调用更改为:

$steam->convertToSteamID

你应该没事。