Your Location is: Home > Php

How to add 'stream resource' return type to function in PHP

From: Kenya View: 1437 Keutelvocht 


I am trying to add a return type to my function that is getting a file of the resource type, but I cant figure out what return type to add? I get an error that my return is a resource and is expected to be a resource witch confuses me :P

Here is my function (more stuff happens in this function to create the filepath but I left it out since it is irrelevant.

private function getMappingExportFile(JobParameters $jobParameters): \resource
    return fopen($filePath,"r");

This is the error I am getting

::getMappingExportFile() must be an instance of resource, resource returned 

If if remove the return type everything works fine, but I prefer to make my code more strict.

Best answer