I see a problem here, that if the param is not passed, $index is not null but an array(). I think we have to do the chaining differently. If you would go with an else if you would also not have to do the removal of the $index part from the $options array as it would only go into the second part, when it is not an array.