no stream declared if `$resource` is not a string ... you should cast `$resource` to string in case `$resource` is not a resource