The expression return $stream could also return false which is incompatible with the documented return type resource. Did you maybe forget to handle an error condition?
If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.