簡體   English   中英

從 PHP 7.4 升級到 8.0 后 Joomla 網站出現錯誤

[英]Error on Joomla Website after upgrading from PHP 7.4 to 8.0

更新 2:

關於錯誤“Call to a member function children() on null”,我找到了這些函數。

public function hasChildren()
{
    return $this->hasChildNodes();
}

public function children($query = null)
{
    $children = array();

    if (!$this->hasChildren()) {
        return $children;
    }

    if ($query == null) {

        foreach ($this->childNodes as $child) {
            if ($child->nodeType == XML_ELEMENT_NODE) {
                $children[] = $child;
            }
        }

        return $children;
    }

    return $this->query(CssSelector::toXPath($query, 'child::'));
}

public function removeChildren()
{
    while ($child = $this->firstChild) {
        $this->removeChild($child);
    }

    return $this;
}

########################################

更新:

我試圖將代碼更改為

public function before(...$data): void
    {
      foreach($data as $item) {

        $item = $this->prepareInsert($item);
        $this->parentNode->insertBefore($item, $this);

     }
 }

這似乎有效,但我得到了更多這些錯誤。 有一次,我將代碼更改為:

public function prepend($data)
{
    $data = $this->prepareInsert($data);

    if (isset($data)) {
        if ($this->hasChildren()) {
            $this->insertBefore($data, $this->firstChild);
        } else {
            $this->appendChild($data);
        }
    }

    return $this;
}

對此:

public function prepend(...$data): void 
{
    foreach($data as $item)
    {
        $item = $this->prepareInsert($item);

        if (isset($item)) {
            if ($this->hasChildren()) {
                $this->insertBefore($item, $this->firstChild);
            } else {
                $this->appendChild($item);
            }
        }
    }
}

現在,我在我的頁面上看到錯誤消息:

Call to a member function children() on null

沒有其他信息。


我們已經安裝了 Joomla 3.10.10 並使用來自 BDThemes 的模板“Effortless”(我們很久以前通過 Envato 購買的)。 該模板基於 Warp 7 框架。 但是,我們的版本已經過時,無法再更新,因為 Envato 上不再提供該模板。 目前我們仍在使用 PHP 7.4,當我們升級到 PHP 8.0 時,我們收到錯誤消息:

“致命錯誤:聲明 Warp\Dom\Element::before($data): void 必須與 DOMElement::before(...$nodes): void in /homepages/13/d238860405/htdocs/homecms_ta/templates /efortless/warp/src/Warp/Dom/Element.php 上線 108"

編碼:

 public function before($data)
    {
        $data = $this->prepareInsert($data);
        $this->parentNode->insertBefore($data, $this);

        return $this;
    } 

不幸的是,我不知道如何解決它。 如果有任何幫助,我將不勝感激。

Element 有一些較新的方法(在 IE 時代不可用),例如:

  1. https://developer.mozilla.org/en-US/docs/Web/API/Element/after
  2. https://developer.mozilla.org/en-US/docs/Web/API/Element/before
  3. https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend
  4. https://developer.mozilla.org/en-US/docs/Web/API/Element/append

顯然較新版本的 DOMElement PHP 也試圖遵循它。 所有這些都是可變參數,但主題的舊代碼可能假設您只有一個要插入的元素。

圍繞它的 go (最小更改)的最簡單方法可能是使用可變參數...$your_variable_name as $data ,然后在您的數據周圍使用foreach($your_variable_name as $data){...} 而且我們必須看看是否還有其他副作用(如果有人曾經使用過$element -> before($oneThing) -> before($anotherThing) ,第二個會失敗(因為第一個before的返回類型是void ,與$this的舊返回不同,您可以在此之后直接使用->before )。
return $this可能不會被使用(不過我不確定)。

例如:

public function before(...$nodes): void
{
    foreach($nodes as $data){
        $data = $this->prepareInsert($data);
        $this->parentNode->insertBefore($data, $this);
    }
   // return $this; 
}

前置

public function prepend(...$nodes): void 
{ 

    foreach($nodes as $data){
        $data = $this->prepareInsert($data); 
        if (isset($data)) { 
            if ($this->hasChildren()) { 
            $this->insertBefore($data, $this->firstChild); 
            } else { 
                $this->appendChild($data); 
            } 
        }
   }
   // return $this; 
} 

(請注意,我無法自己測試,因為我沒有您使用的模板的完整代碼)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM