Req->Bug #69056 [Opn->Fbk]: Typecasting resources to integers should be defined

From: Date: Mon, 16 Feb 2015 00:34:28 +0000
Subject: Req->Bug #69056 [Opn->Fbk]: Typecasting resources to integers should be defined
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190707@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 Updated by: requinix@php.net Reported by: grzegorz129 at gmail dot com Summary: Typecasting resources to integers should be defined -Status: Open +Status: Feedback -Type: Feature/Change Request +Type: Bug -Package: *Programming Data Structures +Package: Scripting Engine problem PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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 (#190707) next »