Jump to content

PHP 8.0 How to correct if ( count($this::$sources) > 0 )


Recommended Posts

Hi all,

I have recently upgraded to php 8.0 and some of the scripts in a wordpress plugin

now don't work.

One of them is because of count needing to be an array.

Should I just change this code 

Quote

if ( count($this::$sources) > 0 )

 

to this ?

 

Quote

if ( count(array($this::$sources)) > 0 )

If not, what would be the correct sintax?

 

Thanks

OK - thanks for reply.

This is a plugin which I didn't write so I am just trying to update it.

Just above the code this comment is written:

    // If there are sources, show a box of recently added

Maybe I could replace that line of code with:

Quote

if (!empty($this::$sources) :

Here is more of the code ...

      // If there are sources, show a box of recently added
  if ( count($this::$sources) > 0 ) :

?>
       <div id="tube-vc-recent-channels-module">

        <h3>
          <?php _e( 'Recently added Channels &amp; Playlists', 'yt-revolution' ); ?>
        </h3>

        <ul style="list-style: none; padding-left:.25em;">

          <?php

            $count = 0;

            foreach ( $this::$sources as $source ):

              $count++;

              if ( $count > 5 ):
                continue;
              endif;

        

 

Edited by David-London

Before you guess the correction code, see what it contains when you get the error

var_dump($this::$sources);

and find where it is being initialized (probably in it's class' constructor

Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.