gettype and unknown type in php

后端 未结 2 480
再見小時候
再見小時候 2021-02-04 07:07

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,

相关标签:
2条回答
  • 2021-02-04 07:52

    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 讨论(0)
  • 2021-02-04 08:00

    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.

    0 讨论(0)
提交回复
热议问题