Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116131 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53213 invoked from network); 22 Sep 2021 13:25:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Sep 2021 13:25:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C105C180505 for ; Wed, 22 Sep 2021 07:06:42 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 94.23.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 22 Sep 2021 07:06:42 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id F077C5101324; Wed, 22 Sep 2021 14:06:35 +0000 (UTC) Message-ID: Date: Wed, 22 Sep 2021 16:06:33 +0200 MIME-Version: 1.0 Content-Language: en-US To: Matthew Weier O'Phinney , PHP Developers Mailing List References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] BC breaking changes in PHP 8.1 From: pierre-php@processus.org (Pierre) Le 22/09/2021 à 15:29, Matthew Weier O'Phinney a écrit : > Yesterday, I opened an issue regarding a change in the pgsql extension ( > https://bugs.php.net/bug.php?id=81464). > > PHP 8.0 introduced the concept of "resource objects". Where previously we > would have resources, and use `get_resource_type()` when we needed to > differentiate various resources, resource objects give us immutable objects > instead that allow us to type hint. Personally, I think this is wonderful! > > The rollout for 8.0 was incomplete, however, and only touched on something > like 4-6 different resource types. Still, a good start. > > With PHP 8.1, we're seeing the addition of more of these, and it was > encountering one of those changes that prompted the bug I previously linked > to. > > Here's the issue: while overall, I like the move to resource objects, > introducing them in a MINOR release is hugely problematic. > > Previously, you would do constructs such as the following: > > if (! is_resource($resource) || get_resource_type($resource) !== > $someSpecificType) { > // skip a test or raise an exception > } > > Resource objects, however: > > - Return `false` for `is_resource()` checks. > - Raise a warning for `get_resource_type()` checks, and/or report the > resource object class name — which differs from the previous resource names > in all cases. Hello, I'm surprised that is_resource() returns false for resource objects, does anyone knows why it wouldn't return true in such case ? This is a very weird behavior, I'd expect it to return true, moreover this is the most annoying detail of this BC break, in my opinion. I have lots of code using is_resource() but I usually don't bother checking for type (maybe I'm doing it wrong). But I'd also expect get_resource_type() to be deprecated somehow and return backward-compatible values for converted resources to objects. Regards, -- Pierre