Re: BC breaking changes in PHP 8.1
| From: | Pierre | Date: | Wed, 22 Sep 2021 14:06:33 +0000 |
| Subject: | Re: BC breaking changes in PHP 8.1 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116131@lists.php.net to get a copy of this message | ||
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 useHello, 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, -- Pierreget_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: - Returnfalseforis_resource()checks. - Raise a warning forget_resource_type()checks, and/or report the resource object class name — which differs from the previous resource names in all cases.