Re: BC breaking changes in PHP 8.1

From: Date: Thu, 23 Sep 2021 21:29:14 +0000
Subject: Re: BC breaking changes in PHP 8.1
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-116151@lists.php.net to get a copy of this message
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

« previous php.internals (#116151) next »