I've just started to practice with PHP built-in gettype()
and its return value. This function is capable to return testing result such as boolean
, integer
, unknown type
, etc. But among those testing result, there's one caught my eyes: unknown type.
After reading gettype()
and trying to find some reference here, i can not get any.
So, the question is what kind of type can be categorized as unknown type
?
Is it possible or am I just missing reading something?
The gettype() function is an inbuilt function in PHP which is used to get the type of a variable. It is used to check the type of existing variable. Syntax: string gettype ( $var ) Parameter: This function accepts a single parameter $var. It is the name of variable which is needed to be checked for type of variable.
To check data type of any variable, PHP provide a function gettype(). PHP gettype() function returns the data type of the variable value passed as argument and returns a string which is a clear data type of the passed value, like: integer, double, string etc.
The gettype() function gets the type of variable; gettype() is a function that display a data type. The settype function sets the type of variable; the settype() function changes the data type.
The gettype() function returns the type of a variable.
Here is one unknown type for you:
$f = fopen('somefile.txt','r');
echo gettype($f); // resource
fclose($f);
echo gettype($f); // unknown
Basically, whenever a resource pointer is closed, the variable holding the handle will point to an unknown resource. Another example would be with GD'S imagecreate/imagedestroy.
Note: as of PHP 7.2, this no longer holds true. gettype
will return resource (closed)
then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With