我一直在玩弄一個RUNESCAPE hiscore形象的創造者。人們傾向於在論壇上使用這些簽名來簽名。PHP私有變量是「未定義」,雖然它被定義
而返工的一些代碼,我把它弄壞了。我越來越:
Undefined variable: exp in /assets/user.php on line 8 Fatal error: Cannot access empty property in /assets/user.php on line 8
然而,該變量甚至沒有在第8行(我假設的東西,用它做修剪空格)。
這裏是我的user.php的文件
<?php
class User {
public static $names = ["Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking",
"Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining","Herblore", "Agility", "Thieving", "Slayer",
"Farming", "Runecrafting", "Hunter", "Construction", "Summoning","Dungeoneering", "Divination", "Invention"];
private $user;
private $mySkills = [];
private $exp = [];
public function __construct($result) {
$array = explode(",", $result);
$id = 0;
$arrId = 1;
while($arrId < count($result)) {
$this->$mySkills[$id] = $array[$arrId++];
$temp = explode(" ", $array[$arrId++]);
$this->$exp[$id++] = $array[0];
}
}
public function getTotalXp() {
return $this->$exp[0];
}
public function getLevel($skill) {
global $names;
for ($x = 0; $x <= count($names); $x++) {
if(strcasecmp($skill, $names[$x]) == 0) {
return $this->$mySkills[$x];
}
}
return 0;
}
public function getExp($skill) {
global $names;
for ($x = 0; $x <= count($names); $x++) {
if(strcasecmp($skill, $names[$x]) == 0) {
return $this->$exp[$x];
}
}
return 0;
}
}
?>
我正在用$名稱錯誤,但那是因爲我沒有使用在函數全局$名稱。
'$此 - > $ mySkills'和'$此 - > $ exp'是__wrong__語法 –
...寫你對象的屬性爲:'$ this-> mySkills','$ this-> exp'等等 – SergeyLebedev