Re: Re: [RFC] Stream Error Handling Improvements
| From: | Tim Düsterhus | Date: | Tue, 31 Mar 2026 09:59:18 +0000 |
| Subject: | Re: Re: [RFC] Stream Error Handling Improvements | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130513@lists.php.net to get a copy of this message | ||
Hi
Am 2026-03-29 20:25, schrieb Jakub Zelenka:
That both makes sense to me.For the naming ofGood point, I changed it but because it now returns array (no linked list), it's called stream_last_errors(). I also added stream_clear_errors for explicit clearing which might be useful in some situations.stream_get_last_error(): Within PHP we have bothX_get_last_error()andX_last_error(). The latter seems to be more common and also what I would prefer here, because thestream_get_prefix sounds to me like we would get something from a stream, but the returned value is not related to a specific stream, but rather a global.
The RFC and the implementation is updated so please take a look!Thank you. The updated RFC looks really good now. I have some (final?) minor remarks: 1. "// Search for specific codes using array_any (PHP 8.5+)" array_any is already available in PHP 8.4. The same is true for "array_find (PHP 8.5+)" in the same example. But given it's an RFC for PHP 8.6 anyways, we already know that these functions exist, so the hint could just be removed entirely. 2. In the example example "$primary = $errors[0] ?? null;" This can just be
$primary = array_first($errors); (PHP 8.5+). Same for the other examples. The examples should ideally show the cleanest possible code :-)
3. For "StreamErrorCode::is*()"
Can error codes fall into multiple categories or is it always a single one? If it's guaranteed to be a single category, then perhaps a ->getErrorCategory() method returning a StreamErrorCodeCategory enum makes more sense and allow for simpler / more efficient code when folks are interested in checking for multiple different categories. Instead of $code->isNetworkError() || $code->isFileSystemError() they can do `\in_array($code->getErrorCategory(), [StreamErrorCodeCategory::NetworkError, StreamErrorCodeCategory::FileSystemError], true) or use a match()` expression instead.
Best regards
Tim Düsterhus