Please be aware that if you are trying to list an empty mailbox, imap_list will return FALSE as if there was an error instead of an empty array() as one may expect.
Example:
With a brand new account created on your mail server, with an empty INBOX, you will get:
$list = imap_list( $imap_stream, $ref, "INBOX/*");
var_dump( $list );
// bool(false)