0
我是PHP新手,遇到一個錯誤,我無法弄清楚如何解決。任何人都可以幫我弄清楚什麼是錯的?它應該從服務器獲取玩家列表,隨機選擇10個名字,並在類別玩家頭部的div內打印每個名稱。xPaw Minecraft API的問題
我收到此錯誤:
Error: Fatal error: Call to a member function Connect() on a non-object in /home/*/x.php on line 32
這裏是我的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<!--
- Get 10 random players from server
- Add to list
- Display these
-->
<?php
require __DIR__ . '/MinecraftQuery.class.php';
$ip = 'play.whatever.com';
$port = 25565;
$a = 10;
$Query = new MinecraftQuery();
function doAll($ip, $port, $a) {
$xtpli = getPlayersFrom($ip, $port);
$xrfpl = getRandomFromPlayerList($a, $xtpli);
generateHeads($xrfpl);
}
function getPlayersFrom($ip, $port) {
try {
$Query->Connect($ip, $port);
$pLi = $Query->GetPlayers();
return $pLi;
} catch (MinecraftQueryException $e) {
echo "An error occured (" . $e->getMessage() . ").";
}
}
function getRandomFromPlayerList($a, $list) {
$tpLi = $list;
$rstpLi = array_shuffle(array_unique($tpLi));
$sliLi = array_slice($rstpLi, 0, $a);
return $sliLi;
}
function array_shuffle($array) {
if (shuffle($array)) {
return $array;
} else {
return FALSE;
}
}
function generateHeads($list) {
foreach ($list as $rp){
echo '<div class="player-head"><img src="https://minotar.net/avatar/' . $rp . '/100.png"</div>';
}
}
doAll($ip, $port, $a);
?>
</body>
</html>
你想要全球去哪裏?不知道你的意思.. – Foldager
看到我的更新 - 它只是在函數聲明之後。 – halfer