1

次のエラーが表示されますが、それがトリガーされる理由や方法がわかりません。

Fatal error: Cannot access empty property in /home/content/p/l/a/plai1870/html/com/php/Bone/Compiler.php on line 18

18号線は

throw new LogicException($this->$compilers[$language]." is not a supported compiler.");

ここに Compiler.php があります

<?php
namespace Bone;
use LogicException;

class Compiler implements \Bone\Interfaces\Compiler {

    protected $compiler;

    protected $compilers = array(
        "php"           => "PHP",
        "as3"           => "ActionScript3",
        "javascript"    => "Javascript"
    );

    public function __construct($language) {
        $language = strtolower($language);
        if (!isset($this->$compilers[$language])) {
            throw new LogicException($this->$compilers[$language]." is not a supported compiler.");
        }
        $compiler = "\Bone\Compilers\\".$this->$compilers[$language]."\Compiler";
        $this->compiler = new $compiler();
    }

    public function buildDefinition($object, $path = null) {
        return $this->compiler()->buildInterface($object, $path);
    }

    public function buildObject($object, $path = null) {
        return $this->compiler->buildObject($object, $path);
    }   

    public function parameters($method) {
        return;
    }

    public function save($data, $path) {
        return;
    }
}
?>

編集 そして、私はそれを次のように呼び出しています:

$compiler = new \Bone\Compiler("php");
4

2 に答える 2

7

これが最も明白な場合は申し訳ありませんが、次のとおりです。

throw new LogicException($this->$compilers[$language]." is not a supported compiler.");

プロパティが存在しないことが確認されているため、次のようにすべきではありません。

throw new LogicException("$language is not a supported compiler.");

?

編集:

$this->$compilers[$language]
       ^- variable property

そこを削除し$ます:

$this->compilers[$language]

$compilers次に、(未設定の)配列(ローカル変数)内の値の名前を持つプロパティが設定されているかどうかではなく、配列のエントリが設定されているかどうかを確認できます。

開発中は、常に警告と通知 (想像できる最高のエラー レベル) をオンにして、PHP から最初に警告を受けずにこれらの問題に遭遇しないようにしてください。

于 2012-11-07T16:27:38.050 に答える
3

あなたの配列は$this->compilers、ではありません$this->$compilers

$compilers関数に存在しない$this->$compilersため、空のプロパティを探していました。

于 2012-11-07T16:31:20.037 に答える