私は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上ではありません(私はそれはそれは空白をトリミングとは何かだと仮定します)。
は、ここで私は$名前のエラーを得ていたが、私は機能のグローバル$名を使用していなかったので、それはだった
<?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;
}
}
?>
私User.phpがファイルです。
'$この - > $ mySkills'と' $これは - > $ exp'は__wrong__構文 –
...と書きは、あなたの'$ this-> mySkills'、' $ this-> exp'などのオブジェクトのプロパティ – SergeyLebedev