Uncaught TypeError string/array

Have this PHP error in logs:

PHP Fatal error:  Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in D:\...\form_xx\form_xx_form0.php:2900
Stack trace:
#0 D:\...\form_xx\form_xx_form0.php(2900): trim()
#1 D:\...\form_xx\form_xx_apl.php(7137): form_xx_form->Form_Corpo()
#2 D:\...\form_xx\form_xx_apl.php(1688): form_xx_apl->nm_gera_html()
#3 D:\...\form_xx\index.php(3273): form_xx_apl->controle()
#4 {main}
  thrown in D:\...\form_xx\form_xx_form0.php on line 2900

This is the relevant part in the php file:

   <?php if (isset($this->nmgp_cmp_hidden['bestellen_']) && $this->nmgp_cmp_hidden['bestellen_'] == 'off') { $sc_hidden_yes++; ?>
<input type=hidden name="bestellen_<?php echo $sc_seq_vert ?>" value="<?php echo $this->form_encode_input($this->bestellen_) . "\">"; ?>
<?php } else { $sc_hidden_no++; ?>
<?php 
  if ($this->nmgp_opcao != "recarga") 
  {
      $this->bestellen__1 = explode(";", trim($this->bestellen_));
  } 
  else
  {
      if (empty($this->bestellen_))
      {
          $this->bestellen__1= array(); 
          $this->bestellen_= "";
      } 
      else
      {
          $this->bestellen__1= $this->bestellen_; 
          $this->bestellen_= ""; 
          foreach ($this->bestellen__1 as $cada_bestellen_)
          {
             if (!empty($bestellen_))
             {
                 $this->bestellen_.= ";"; 
             } 
             $this->bestellen_.= $cada_bestellen_; 
          } 
      } 
  } 
?> 

The application is a form where a user can select multiple items.
It seems to me like this is SC causing this error but there is also some user code in events which might be causing problems but I have not found it in this file.