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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php