I'm currently investigating some PHP-code and I'm trying to make it more up to date. I found a function, which retrieves a filehandle (via fopen
).
The returntype is stream
. I checked it with
$handle = fopen("myfile.csv", "r");
var_dump(get_resource_type($handle));
As mentioned, the type seems to be stream
.
When I try to pass this object to a function, I can't force the type with stream.
public function parseHandle(stream $handle){}
ends up with this error-message:
Argument 1 passed to parseHandle must be an instance of stream, resource given.
When I try to change the signature to function parseHandle(resource $resource)
it yields the following error:
Argument 1 passed to parseHandle must be an instance of resource, resource given
What is the correct datatype and how should I use it in the arguments?
I know I can use is_resource
in the very first lines of my function to verify it, but I still wonder.