我有另一个问题。
当我尝试从以下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>
任何人都知道如何解决这个问题吗?
答案 0 :(得分:1)
this
周围的语法完全错误。而不是
return this::$_serverStatus;
您应该使用
return $this->_serverStatus;
同样,您对GetStatus()
的内部呼叫应为
if ($this->GetStatus() != 'Online') {
// ...
我建议您从这里开始阅读 - http://php.net/manual/en/language.oop5.basic.php