Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Variable Handling Functions : get_resource_type

get_resource_type

Returns the resource type (PHP 4 >= 4.0.2, PHP 5)
string get_resource_type ( resource handle )

Example 2585. get_resource_type() example

<?php
// prints: mysql link
$c = mysql_connect();
echo
get_resource_type($c) . "\n";

// prints: file
$fp = fopen("foo", "w");
echo
get_resource_type($fp) . "\n";

// prints: domxml document
$doc = new_xmldoc("1.0");
echo
get_resource_type($doc->doc) . "\n";
?>

Code Examples / Notes » get_resource_type

jdhawk _at_ gmail

In PHP5 (on Linux), the above example identifies the "file" handler as a 'stream', not 'file'.
This can be particularly worrisome if you're trying to determine the type of stream using this function.
The alternative is to use <?php stream_get_meta_data() ?>, which returns an array containing "stream_type (string) - a label describing the underlying implementation of the stream."


hessodreamy

Furthermore, this function returns 'stream' on php 4.3 on windows & linux.
You if you want to differentiate between a file resource and other stream resources, as stated before stream_get_meta_data() gives you an array which, on my system, contains the following elements which might suggest a file handle:
[wrapper_type] => plainfile
[stream_type] => STDIO
However I've only compared this to a stream from a url, so I include this only as a suggestion.


Change Language


Follow Navioo On Twitter
debug_zval_dump
doubleval
empty
floatval
get_defined_vars
get_resource_type
gettype
import_request_variables
intval
is_array
is_binary
is_bool
is_buffer
is_callable
is_double
is_float
is_int
is_integer
is_long
is_null
is_numeric
is_object
is_real
is_resource
is_scalar
is_string
is_unicode
isset
print_r
serialize
settype
strval
unserialize
unset
var_dump
var_export
eXTReMe Tracker