Bug #69056 [Com]: Typecasting resources to integers should be defined

From: Date: Mon, 23 Feb 2015 22:40:23 +0000
Subject: Bug #69056 [Com]: Typecasting resources to integers should be defined
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190923@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69056&edit=1 ID: 69056 Comment by: grzegorz129 at gmail dot com Reported by: grzegorz129 at gmail dot com Summary: Typecasting resources to integers should be defined Status: Feedback Type: Bug Package: Scripting Engine problem PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: You're right - it casts to integers just fine and I just missed that in documentation (I was looking for something related to streams, not exactly resources ;)). To be curious I'm surprised it doesn't return actual FD# when casted to number. I started thinking that counting up without reusing number (which mostly will create mess if their aren't tightly tied to particular sockets like FDs) might be fatal at some point - unfortunately it ended as next bug report. I think this report can be closed, and further investigation should be taken under bug #69109. Previous Comments: ------------------------------------------------------------------------ [2015-02-16 00:34:27] requinix@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. I don't get any warnings. http://3v4l.org/LMVon Meanwhile, both the documentation and the spec say resources are converted to their number, so any warning produced would (probably) be a bug. http://php.net/manual/en/language.types.integer.php >If a resource is converted to an integer, then the result will be the unique >resource number assigned to the resource by PHP at runtime. https://github.com/php/php-langspec/blob/master/spec/08-conversions.md >If the source is a resource, the result is the resource's unique ID. ------------------------------------------------------------------------ [2015-02-15 13:58:41] grzegorz129 at gmail dot com Description: ------------ Typecasting resources to integers became common practice when used with stream_select(). It provides fast & consistent between versions method to locate sockets returned by stream_select(), however it's still undefined by PHP documentation (manual for integer type clearly warns about casting unknown types to integers: "The behaviour of converting to integer is undefined for other types. Do not rely on any observed behaviour, as it can change without notice."). From some time now stream_select() preserves assoc. array keys (which enables usage of eg. local socket name as key), but it also cannot be considered stable due to doc bug #68798. Expected result: ---------------- Casting resources to integers should be documented. Casting resource to integer should produce unique number of resource (which is actual result, but not documented). Actual result: -------------- Casting resource to integer produces strict warning. Actual integer produced is the same as shown by var_dump(). Example: class StreamServer#1 (1) { private $zeroStream => resource(22) of type (Direct I/O File Descriptor) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69056&edit=1

« previous php.bugs (#190923) next »