Answers.Body: <pre class="lang-php prettyprint-override"><code>$thumbs = $entry-&gt;pdfThumbnailImage-&gt;all();
  
  if(count($thumbs) &gt; 0){
   //more checking code
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-15T07:14:13.757Z
Answers.LastActivityDate: 2023-08-15T07:14:13.757Z
Answers.UserDisplayName: andrew.welch
Body: <p>I am trying to migrate a plugin from Craft 3 to Craft4 .
  The plugin basically checks the entry for a pdf asset and create a thumbnail asset from the PDF using Imagick to save with the entry.</p>
  <p>I use to check for the presence of a thumbnail by doing :</p>
  <pre><code>$thumbs = $entry-&gt;pdfThumbnailImage;
  
  if(count($thumbs) &gt; '0'){
   //more checking code
  }
  </code></pre>
  <p>Since php8.1 count above returns:</p>
  <pre><code>count(): Argument #1 ($value) must be of type Countable|array, craft\elements\db\AssetQuery given
  </code></pre>
  <p>I am super daft and rusty and wondered how other people are handling the change in count to check for a custom field asset.</p>
  
Tags: <plugin-development><craft4>
Title: Plugin migration - how to handle count in php8.1
ThreadText: # Plugin migration - how to handle count in php8.1
  
  (Asked by: username_0 on 2023-08-15)
  
  I am trying to migrate a plugin from Craft 3 to Craft4 .
  The plugin basically checks the entry for a pdf asset and create a thumbnail asset from the PDF using Imagick to save with the entry.
  
  I use to check for the presence of a thumbnail by doing :
  
  ```
  $thumbs = $entry->pdfThumbnailImage;
  
  if(count($thumbs) > '0'){
   //more checking code
  }
  
  ```
  
  Since php8.1 count above returns:
  
  ```
  count(): Argument #1 ($value) must be of type Countable|array, craft\elements\db\AssetQuery given
  
  ```
  
  I am super daft and rusty and wondered how other people are handling the change in count to check for a custom field asset.
  
  **Tags:** plugin-development, craft4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-08-15. Score: 2
  
  ```php
  $thumbs = $entry->pdfThumbnailImage->all();
  
  if(count($thumbs) > 0){
   //more checking code
  }
  
  ```
  
  
  ---
  
  