0

我还有一个问题。

当我尝试从以下 php 类获取数据时出现内部服务器错误:

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: -Ryuk-
 * Date: 21/11/12
 * Time: 17:08
 * To change this template use File | Settings | File Templates.
  */
class game
{
    private $_serverStatus = "Online";
    private $_numOnline = "32";
    private $_maxPlayers = "50";
    private $_messageOfTheDay = "Welcome to game!";
    private $_Players = "Falcubar2011;Zacardor;";

public function GetStatus()
{
    return this::$_serverStatus;
}

public function GetNumOnline()
{
    return this::$_numOnline;
}

public function MaxPlayers()
{
    return this::$_maxPlayers;
}

public function GetMOTD()
{
    return this::$_messageOfTheDay;
}

public function GetPlayers()
{
    return this::$_Players;
}

public function GetServiceColour()
{
    if(this::GetStatus() != "Online")
        return "#FF0000";
    else
        return "#008000";
}
}

我试图这样称呼它(在 index.php 中)我把它去掉了,所以你不会得到所有的垃圾。

$mc = new game();

  <div id="Stats">
        <div id=roundedbox>
            <h1>Info</h1>
            <p>
            <p><strong>IP:</strong> play.game.com</p>
            <br>

            <p>Slots: <?php print $mc->GetNumOnline(); ?> / <?php print $mc->MaxPlayers(); ?></p>
            <br>
            <p>Status: <?php print $mc->GetStatus(); ?></p>
            <br>
            <p>MOTD: <?php print $mc->GetMOTD(); ?></p>
            </div>
    </div>

任何人都知道如何解决我遇到的这个问题?

4

1 回答 1

1

您的语法this完全错误。代替

return this::$_serverStatus;

你应该使用

return $this->_serverStatus;

同样,您的内部调用GetStatus()应该是

if ($this->GetStatus() != 'Online') {
    // ...

我建议您从这里开始阅读 - http://php.net/manual/en/language.oop5.basic.php

于 2013-01-09T03:47:32.527 回答