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

CC BY-SA 3.0
2015-08-25T02:17:09.937Z
Is this a plugin that you've developed? Is it maybe saving the colours as a list of colours or RGB values?
Rick
CC BY-SA 3.0
2015-08-25T02:46:01.603Z
I voted you up in spite of your gleeful misspelling of the word "colors". :)
Brad Bell
CC BY-SA 3.0
2015-08-25T07:38:00.870Z
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.
Sam Hibberd
CC BY-SA 3.0
2015-08-25T13:34:55.887Z
@BradBell he spelled it perfectly fine.
Luke Holder
CC BY-SA 3.0
2015-08-25T20:14:13.337Z
So if you insert a line before line 86 of `FruitStyle_PaletteFieldType.php` and add `var_dump($settings["colours"]);` ... does it report a string?
Rick
CC BY-SA 3.0
2015-08-25T02:10:01.887Z
2015-08-25T02:10:01.887Z
Rick
<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>

<plugin-development>
Array expecting string error when fieldtype is used within matrix
# 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(),
    ));
}

**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**: @BradBell 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?  

---

