I have the following switch statement, which should be returning an array of messages sent to/from a user:

```
<?php
// Load libs, verify user
require_once '../bootstrap.php';

switch ($_GET['folder']) {
  case 'inbox':
    $messages = Message::sentToUser($userId);
    break;

  case 'sent':
    $messages = Message::sentByUser($userId);
    break;

  default:
    $messages = Message::sentToUser($userId);
    break;
}

$json = json_encode($messages);
echo $json;

```

Messages.php

```
  public static function sentToUser($user_id)
  {
    $messages = DB::table('messages')
                  ->order_by('id', 'DESC')
                  ->where('sent_to_id', '=', $user_id)
                  ->where('show_to_receiver', '=', 1)
                  ->get();

    return ($messages) ? $messages : array();
  }

```

Everything works fine if I pass in a `folder` param:

```
[
  {
    id: "1"
    title: "Test Message"
    message: ""
    read: "0"
    date_sent: "2014-05-14 15:08:43"
    date_read: null
    sent_from_id: "5"
    sent_to_id: "40"
  }
]

```

However, in the default case (no folder param given), PHP throws `PHP Notice: Undefined index: folder` (expected), and `$messages` is returned as an object, not array:

```
{
  id: "1"
  title: "Test Message"
  message: ""
  read: "0"
  date_sent: "2014-05-14 15:08:43"
  date_read: null
  sent_from_id: "5"
  sent_to_id: "40"
}

```

I would have expected `$messages` to be set to the same thing if `$_GET['folder']` is `'inbox'` or `undefined`. Any ideas as to the root of the inconsistency?