Answers.Body: <p>It appears as though <code>$settings['colours']</code> is an array... which you're then trying to trim and explode.</p>
  
  <p>Can you <code>var_dump($settings['colours'])</code>?</p>
  
  <p>p.s. Nice to see "colours" spelt "correctly" :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T02:17:09.937Z
Answers.Text: Is this a plugin that you've developed? Is it maybe saving the colours as a list of colours or RGB values?
Answers.UserDisplayName: Rick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T02:46:01.603Z
Answers.Text: I voted you up in spite of your gleeful misspelling of the word "colors". :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T07:38:00.870Z
Answers.Text: Gents, this is the confusing bit that I was trying to explain (badly) when var_dump or dump() in the template its says that it's a string!! Baffled.
Answers.UserDisplayName: Sam Hibberd
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T13:34:55.887Z
Answers.Text: @BradBell he spelled it perfectly fine.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T20:14:13.337Z
Answers.Text: So if you insert a line before line 86 of `FruitStyle_PaletteFieldType.php` and add `var_dump($settings["colours"]);` ... does it report a string?
Answers.UserDisplayName: Rick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T02:10:01.887Z
Answers.LastActivityDate: 2015-08-25T02:10:01.887Z
Answers.UserDisplayName: Rick
Body: <p>Im getting an expecting string given array error on a variable in my fieldtype. When output / dumped to the template it is a string. This only happens when used within matrix field.</p>
  
  <p>The trim function here is the specific line throwing the error:</p>
  
  <pre><code>$settings['colours'] = explode(',', str_replace(' ', '', trim($settings['colours'])));
  </code></pre>
  
  <p>getInputHtml() &amp; prepValue()</p>
  
  <pre><code>public function prepValue($value)
  {
      $colour = new FruitStyle_PaletteModel();
  
      if(is_array($value))
      {
          $colour-&gt;hex = $value['hex'];
          $colour-&gt;opacity = $value['opacity'];
      }
  
      return $colour;
  }
  
  public function getInputHtml($name, $value)
  {
      craft()-&gt;templates-&gt;includeJsResource('fruitstyle/js/FruitPalette.js');
      craft()-&gt;templates-&gt;includeCssResource('fruitstyle/css/palette.css');
      craft()-&gt;templates-&gt;includeCssResource('fruitstyle/fonts/fruiticons/style.css');
  
      $id = craft()-&gt;templates-&gt;formatInputId($name);
      craft()-&gt;templates-&gt;includeJs('new FruitPalette("'.craft()-&gt;templates-&gt;namespaceInputId($id).'");');
  
      // String or JSON
      $settings = $this-&gt;getSettings();
      if(filter_var($settings['colours'], FILTER_VALIDATE_URL))
      {
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_URL, $settings['colours']);
          $colours = curl_exec($ch);
          curl_close($ch);
          $settings['colours'] = JsonHelper::decode($colours, true);
      }
      else
      {
          $settings['colours'] = explode(',', str_replace(' ', '', trim($settings['colours'])));
      }
  
      return craft()-&gt;templates-&gt;render('fruitstyle/_fieldtype/palette/input', array(
          'id' =&gt; $id,
          'name' =&gt; $name,
          'value' =&gt; $value,
          'settings' =&gt; $settings,
          'specialOptions' =&gt; $this-&gt;_getSpecialOptions(),
      ));
  }
  </code></pre>
  
  <p><a href="https://i.sstatic.net/j29XG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/j29XG.png" alt="PHP Error"></a></p>
  
Tags: <plugin-development>
Title: Array expecting string error when fieldtype is used within matrix
ThreadText: # Array expecting string error when fieldtype is used within matrix
  
  (Asked by: username_0 on 2015-08-24)
  
  Im getting an expecting string given array error on a variable in my fieldtype. When output / dumped to the template it is a string. This only happens when used within matrix field.
  
  The trim function here is the specific line throwing the error:
  
  ```
  $settings['colours'] = explode(',', str_replace(' ', '', trim($settings['colours'])));
  
  ```
  
  getInputHtml() & prepValue()
  
  ```
  public function prepValue($value)
  {
      $colour = new FruitStyle_PaletteModel();
  
      if(is_array($value))
      {
          $colour->hex = $value['hex'];
          $colour->opacity = $value['opacity'];
      }
  
      return $colour;
  }
  
  public function getInputHtml($name, $value)
  {
      craft()->templates->includeJsResource('fruitstyle/js/FruitPalette.js');
      craft()->templates->includeCssResource('fruitstyle/css/palette.css');
      craft()->templates->includeCssResource('fruitstyle/fonts/fruiticons/style.css');
  
      $id = craft()->templates->formatInputId($name);
      craft()->templates->includeJs('new FruitPalette("'.craft()->templates->namespaceInputId($id).'");');
  
      // String or JSON
      $settings = $this->getSettings();
      if(filter_var($settings['colours'], FILTER_VALIDATE_URL))
      {
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_URL, $settings['colours']);
          $colours = curl_exec($ch);
          curl_close($ch);
          $settings['colours'] = JsonHelper::decode($colours, true);
      }
      else
      {
          $settings['colours'] = explode(',', str_replace(' ', '', trim($settings['colours'])));
      }
  
      return craft()->templates->render('fruitstyle/_fieldtype/palette/input', array(
          'id' => $id,
          'name' => $name,
          'value' => $value,
          'settings' => $settings,
          'specialOptions' => $this->_getSpecialOptions(),
      ));
  }
  
  ```
  
  [![PHP Error](https://i.sstatic.net/j29XG.png)](https://i.sstatic.net/j29XG.png)
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-25. Score: 2
  
  It appears as though `$settings['colours']` is an array... which you're then trying to trim and explode.
  
  Can you `var_dump($settings['colours'])`?
  
  p.s. Nice to see "colours" spelt "correctly" :)
  
  > **Comments:**
  > **username_1**: Is this a plugin that you've developed? Is it maybe saving the colours as a list of colours or RGB values?  
  > **username_2**: I voted you up in spite of your gleeful misspelling of the word "colors". :)  
  > **username_0**: Gents, this is the confusing bit that I was trying to explain (badly) when var_dump or dump() in the template its says that it's a string!! Baffled.  
  > **username_3**: @username_2 he spelled it perfectly fine.  
  > **username_1**: So if you insert a line before line 86 of `FruitStyle_PaletteFieldType.php` and add `var_dump($settings["colours"]);` ... does it report a string?  
  
  ---
  
  