我一直在玩弄一个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