开发者

gettype and unknown type in php

开发者 https://www.devze.com 2022-12-23 12:06 出处:网络
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 开发者_开发百科

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消