Hi,

Am 22.09.21 um 15:29 schrieb Matthew Weier O'Phinney:
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.

Would it be helpful if is_resource() raises an error if a resource object is provided as argument instead of returning false? (Should that be limited to the newly introduced resource objects in 8.1? Would a deprecation be enough?)

Of course, existing code would not work with that change. But you should be able to spot the error and fix it.

It should be possible to write code that works with PHP < 8.1 and >= 8.1. Combined with Rowans idea of a Resource base class or interface that might even be easier?

(I assume it's of no additional help to change get_resource_type() to accept resource objects and return the same result as the former, corresponding resource type.)

Regards
Thomas

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to