0

ここには について約 100 の異なる質問があるようですCreating default object from empty value。それらのどれも私の問題に実際に役立つようには見えません。

メソッドで同じクラスの子オブジェクトを割り当てています。これにより、Creating default object from empty valueエラーが発生します。

class myClass {


    function __construct($rootName, $allowHTML = false, $endTag = true) {
        $this->rootElement = $rootName;
        $this->elements = array();
        $this->attributes = array();
        $this->value = "";
        $this->allowHTML = $allowHTML;
        $this->endTag = $endTag;
        $this->styles = array();
        $this->childID = 0;
    }

    // ... OTHER METHODS HERE (ALL PROPERTIES DECLARED)

    function assignElement(&$theElement) {
        // Get the index.
        $index = count($this->elements);

        // Assign the element.
        $this->elements[$index] = $theElement;

        if (get_class($theElement) == get_class($this)) {
            $this->elements[$index]->childID = $index;
        }

        // Return the node.
        return $this->elements[$index];
    }
}

でエラーが発生し$this->elements[$index]->childID = $index;ます。これを適切に処理するにはどうすればよいですか?

4

1 に答える 1

2

NULLに渡っているようですassignElementget_class引数なしまたは引数として null で呼び出された場合、それが定義されているオブジェクトのクラスが返されるため、ifnull 値に対して条件が真になります。最初に使用する必要がありますis_object

于 2012-12-27T15:39:33.270 に答える