php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28016 is_resource() returns false for resources of type "Unknown"
Submitted: 2004-04-15 21:15 UTC Modified: 2016-09-29 11:50 UTC
Votes:11
Avg. Score:4.3 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:4 (44.4%)
Same OS:4 (44.4%)
From: php at ter dot dk Assigned: cmb (profile)
Status: Closed Package: *General Issues
PHP Version: * OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at ter dot dk
New email:
PHP Version: OS:

 

 [2004-04-15 21:15 UTC] php at ter dot dk
Description:
------------
(version of PHP is 4.3.6, not 4.3.6RC3, but I wasn't able to select that)

If a resource for some reason is of type "Unknown", is_resource() returns false. Though, gettype() still returns "resource" as type, as always.

This behaviour in is_resource() has changed between 4.3.5 and 4.3.6.

I'm guessing here, but the new behaviour could be related to changes introduced to fix bug 27822 (which was fixed in between 4.3.5 and 4.3.6).

In my example I'm using php-imlib to gain an object of type "Unknown". Even though it isn't an official extension, there still is some inconsistency between gettype() returning "resource" and is_resource() returning false. In other words, it's the inconsistency between is_resource() and gettype() I see as the bug.

Example is also available at: http://stock.ter.dk/resource_error.php

Reproduce code:
---------------
$i = imlib_create_image(100,200);
var_dump($i);
var_dump(gettype($i));
var_dump(is_resource($i));


Expected result:
----------------
resource(2) of type (Unknown)
string(8) "resource"
bool(true)


Actual result:
--------------
resource(2) of type (Unknown)
string(8) "resource"
bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-15 22:35 UTC] sniper@php.net
Derick, IMO, the fix for bug #27822 was incorrect. 
Resource is still a resource even if it's closed..
Or you need to unset the variable with any 'close'.. :)

 [2004-04-16 03:15 UTC] derick@php.net
No, the fix was correct. Close() in this case destroyed the resource data in the variable, so it's no longer a resource anymore. I think the correct thing to do here is to make gettype() not show "resource" either.
 [2004-04-16 08:37 UTC] php at ter dot dk
But will it solve the problem in my situation? After all, I do have a resource by hand, and would be pretty sad if other functions wouldn't recognize it as a resource.

I do agree though that making gettype not return "resource" for a closed resource (since is_resource() already does that). I just don't like the idea that these functions might not recognize my resource at all.

- Peter Brodersen
 [2004-04-16 11:05 UTC] derick@php.net
If the imlib extension gives it a proper name then it should work fine, so I think it's also a bug there.
 [2004-04-16 15:11 UTC] sniper@php.net
Derick: I agree, just change gettype() too.

And imlib / other extensions using the wrong way in registering resources should be fixed. The 'non-named' resource is meant for something else..

 [2004-07-19 19:16 UTC] php at afdelingp dot dk
I have created a patch for Piotr Pawlow's version of php_imlib 0.3, fixing this issue for imlib (though I think the PHP behavior is strange at best).

http://www.afdelingp.dk/files/php-4.3.8-imlib-rsrc.diff

Best regards,
Morten K. Poulsen
 [2010-12-20 14:00 UTC] jani@php.net
-Package: Feature/Change Request +Package: *General Issues -PHP Version: 5CVS, 6CVS (2008-10-28) +PHP Version: *
 [2013-01-06 16:05 UTC] derick@php.net
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
 [2014-08-22 12:09 UTC] justinasu at gmail dot com
this is still reproducible in PHP 5.4.30, how is this not fixed yet?
 [2016-09-29 11:50 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-09-29 11:50 UTC] cmb@php.net
> In other words, it's the inconsistency between is_resource() and
> gettype() I see as the bug.

And this inconsistency has been resolved long ago, see
<https://3v4l.org/qnk41>, so this ticket can be closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 22:01:28 2024 UTC