get_resource_type
Return resource type
Return resource type:
<span class="token php language-php"><span class="token delimiter important"><?php</span> <span class="token variable">$file</span> <span class="token operator">=</span> <span class="token function">fopen</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"test.txt"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"r"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token keyword">echo</span> <span class="token function">get_resource_type</span> <span class="token punctuation">(</span> <span class="token variable">$file</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span> <span class="token delimiter important">?></span></span>
$file is a file resource opened through fopen() function. get_resource_type($file) will return the type of the resource, usually "stream" . If the file does not exist or cannot be opened, fopen() returns FALSE , but no error checking is performed in this example. In practical applications, the return value of fopen() should be checked to ensure that the file has been opened successfully. If $file is not a valid resource, get_resource_type($file) will return NULL and may generate an error. In versions prior to PHP 5.3, it will return FALSE instead of NULL .