Bug #75868 [Opn->Nab]: is_resource() gettype() get_resources() inconsistent result on closed resource
| From: | cmb@php.net | Date: | Thu, 25 Jan 2018 13:41:48 +0000 |
| Subject: | Bug #75868 [Opn->Nab]: is_resource() gettype() get_resources() inconsistent result on closed resource | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213703@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75868&edit=1
ID: 75868
Updated by: cmb@php.net
Reported by: bobonov at gmail dot com
Summary: is_resource() gettype() get_resources() inconsistent
result on closed resource
-Status: Open
+Status: Not a bug
Type: Bug
Package: Variables related
Operating System: Ubuntu 17.10
PHP Version: 7.2.1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> Checking the closed resource with:
> is_resource() return false.
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is documented[1] behavior:
| is_resource() is not a strict type-checking method: it will
| return FALSE if var is a resource variable that has been closed.
[1] <http://www.php.net/manual/en/function.is-resource.php#refsect1-function.is-resource-notes>
Previous Comments:
------------------------------------------------------------------------
[2018-01-24 14:31:43] bobonov at gmail dot com
Description:
------------
Checking the closed resource with:
gettype() return resource (closed)
get_resources() list it as resource
is_resource() return false.
There is an ancient Bug #42797 (php 4.3.6) that is relevant to this bug
Test script:
---------------
<?php
$a = fopen('http://www.google.com',
'r');
echo "$a : the type is " . gettype($a)."\n"; // resource
var_dump(is_resource($a)); // true
print_r(get_resources());
fclose($a);
echo "$a : the type is " . gettype($a)."\n"; // resource closed
var_dump(is_resource($a)); // false
print_r(get_resources());
Expected result:
----------------
I expect is_resource() to return true since get_resources() and gettype() see the var as resource
Actual result:
--------------
Resource id #6 : the type is resource
bool(true)
Array
(
[1] => Resource id #1
[2] => Resource id #2
[3] => Resource id #3
[4] => Resource id #4
[6] => Resource id #6
)
Resource id #6 : the type is resource (closed)
bool(false)
Array
(
[1] => Resource id #1
[2] => Resource id #2
[3] => Resource id #3
[4] => Resource id #4
[6] => Resource id #6
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75868&edit=1