Cannot Use A Scalar Value As An Array - PHP Octobercms

- 1 answer

I had this working before but no it doesn't. I have an array in my model, In a component I call the array and try to set as a page variable but it refuses to have it.

Model - Profile.php

public static $ajaxSortingOptions = array(
        'count_views desc' => 'Most Popular',
        'count_photos desc' => 'Most Photos',
        'count_videos desc' => 'Most Videos',
        'created_at desc' => 'Recent Members',
        'random' => 'Random'

Component - Profiles.php

public $sortingOptions;

public function getAjaxSortOrderOptions()
        return Profile::$ajaxSortingOptions;

public function onRun()


        $this->page['sortingOptions'] = $this->getAjaxSortOrderOptions();


and in my view

<select class="dropdown" name="Filter[sort]">
                                        <option value="">Select</option>
                                        {% for key,value in sortingOptions  %}
                                            <option value="{{key}}">{{ value }}</option>
                                        {% endfor %}

Cannot use a scalar value as an array

/var/www/public/plugins/libre/membership/components/Profiles.php line 147

the line in question

$this->page['sortingOptions'] = $this->getAjaxSortOrderOptions();


Please see this simple test example:

class foo{

    protected $page=1;

    public function __construct(){

        $this->page['bar'] = 'hello';


new foo;



<br />
<b>Warning</b>:  Cannot use a scalar value as an array in <b>[...][...]</b> on line <b>9</b><br />

I just wanted to put this in here, so the answer is an acutal answer.

Thanks, I had this bit of code in $this->page = $this->page['page'] = $this->profiles->currentPage(); somewhere else

As I said in the comments it's very easy to do things like this as they are valid at the time. Much like using = in place of == it can be really hard to spot the bug only the cascade effect it causes.