tags:

views:

95

answers:

2

i just start 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 try 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 ?

+2  A: 

According to the PHP source code it's the "default" case in the switch statement for that function. My guess is that is is there way of handling an internal error.

Kendall Hopkins
PHP just got a bit more messy in my eyes.
lamas
+1 for checking with the sourcecode. The downvote is totally undeserved in my opinion.
Gordon
+5  A: 

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.

Gordon
Wow, PHP. Outputting the "closed" file resource still shows "Resource id #x" but it's type is suddenly unkown. +1 Nice answer, though
lamas
thanks, this is great answer. ;D
justjoe
Another fun fact. gettype returns "object" for closures due to the way it was implemented.
Kendall Hopkins