function hoge() {
  if (条件) {
    $str = "string";
    return $str;
  }
  return true;
}

こんな感じで、条件によって返り値の型が違うのですが、
問題ないでしょうか?