简体   繁体   中英

Error on Joomla Website after upgrading from PHP 7.4 to 8.0

Update 2:

Regarding the error "Call to a member function children() on null", I found these functions.

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;
}

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

Update:

I tried to change the code to

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

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

     }
 }

This seems to work, but I get more of those errors. At one point I changed the code from:

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;
}

to 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);
            }
        }
    }
}

Now, I get on my page the error message:

Call to a member function children() on null

There are no other information.


we have installed Joomla 3.10.10 and use the template "Effortless" from BDThemes (which we bought a long time ago via Envato). The template is based on the Warp 7 framework. However, our version is outdated and can no longer be updated, as the template is no longer available on Envato. Currently we are still using PHP 7.4, when we upgrade to PHP 8.0 we get the error message:

"Fatal error: Declaration of Warp\Dom\Element::before($data): void must be compatible with DOMElement::before(...$nodes): void in /homepages/13/d238860405/htdocs/homecms_ta/templates/effortless/warp/src/Warp/Dom/Element.php on line 108"

The code:

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

        return $this;
    } 

Unfortunately, I don't know how to fix it. I would be very grateful for any help.

There are some newer methods of Element (not available during the age of IE), for example:

  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

Apparently newer versions of DOMElement PHP tried to follow it too. All of those are variadic, but the old code of the theme may have assumed that you only had one element to insert.

The easiest way to go around it (minimal change) is probably to use a variadic argument ...$your_variable_name as $data , then use foreach($your_variable_name as $data){...} around your data. And we have to see if there are other side effects (if someone ever uses $element -> before($oneThing) -> before($anotherThing) , the second one would fail (as the return type of the first before is void , unlike the old return of $this where you can use ->before directly after that).
The return $this probably won't get used (I'm not sure about that, though).

For example:

before

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

prepend

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; 
} 

(note that I can't test it myself as I don't have the complete code of the template you used)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM