Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130480 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id E685D1A00BC for ; Sun, 29 Mar 2026 18:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1774808768; bh=beMz86Wtw2S0W5EwMxhMOAwhYWoIz/gwa52NUTreEQE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gegScQNAWCNeXluQO2aq338RxlktvQFcLv9qJDC+Hcu0/YwgnnuXU+nV5knHoP1Ex I8DZ4CLYiMC0KLPsHMNvqDk81/XVxrzI3ZdJaTC2ePMbgWfUIGwxVtcX6A7755yOK0 NrEABbvr17YS/1jSpeh5T8Z0dc0x+Qexx/Ik/gWVAfUYmfGNNmpuXQHwclHfMxPzYj 3KvUov7CfOZw4plm3rz22LjCDixFYe+LW7qE6ZqMjzaGPpXC+wAqCPVWTmX5pCMZbi DzCePuD8nKNQFervYS9mO3HL3AW9t9StkhWy+tXgYMwbmIEh8IvH1Xeh5Jb1XJjW3g AyMLj5aXCW/gg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB4BD180068 for ; Sun, 29 Mar 2026 18:26:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DMARC_NONE,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 29 Mar 2026 18:26:06 +0000 (UTC) Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-7d744d9acbeso1504571a34.1 for ; Sun, 29 Mar 2026 11:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774808761; cv=none; d=google.com; s=arc-20240605; b=N3TCMtsWXo72HXL6fhwrk47gCdCpwIEX1B0FxCukuNyGp4s8PAQD13m8l6iXPk9AHC 3H80IvR2CUh8MDVJX+UybcPZxnvqL2lhRvsBQCKBjtYoRBX/YnYHS7AvuzJd6f/GiBO9 CNPFuaTvRjTk2aruQeie9pS2tABtceaTizT+mnklxWZfqoOizjZTYnmJLry/WagS8d/T 3d3FaF+Mr7OHAj4E6HMSGPpwT7luaacCuYnmMOcghfA5a0tXza9Fj0MjSKYzA4oSFPFD NZuDgWwlPl77NH9UuMRM9cii2EzMWRA7M0oE/93rWaLZ0/TZClTBpZFsS7piWlmXqA5g URlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version; bh=cSHJmPu5ccjYiIQuDHCcPKGsqfuKeMnjsiiWwkZOaQ4=; fh=OD4QmfkPKVb8nK7ULgDqzPLo6PKMhBf6arulVq590tc=; b=EVEOHagHHRIoFnCNM8zqi1swvO1wpuQVKnFJVt2NEbDJmxUKaQNrTrwdjGYBtIJ9K4 fqCbxsRdIW1I+nBrJgIFXIchQI7NgRYHIkuavo1WH9gYrG14DQhvisym42eLkIaLj7lU Vlw5pvgOGxeDZKI+qSJ9Vjthje+Jj+IeX2jTT50IYfgXr4u/+oSogaPpRKFpJ/VD07SU KbyRoW29nFdLYq2q6sZ3qYYxkwESbIAFBYU2/P0LtoF0KHC/OK6jz6zo0rnpL/uVCxqw aUud1fCbC41LWMaPZzfkw6tm9e+Wt0Me2RPMS4/goZk7iWUH+77Ogi9hwv5Fvo/1Gg0x kvTQ==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774808761; x=1775413561; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cSHJmPu5ccjYiIQuDHCcPKGsqfuKeMnjsiiWwkZOaQ4=; b=FeNYSvYxfKGft2G4fELMJSnYEYlAYfpJTBbn1aJ+zRjmgGpBgDnOOrH5Dr/yKfXmYA A33Cnl1HhSrytHPWWN+qbP2Zv8FHfMH8NNXcuLRkzU8g41/ghzA/hPBvZe9fwOn3uA0H E56EHL0wZ4fxa1NlFpvqnrAmvZxni3xsryP2vMLU0IqhkqbWD8fyryc8ZhJ4WSr37cdM V9NRJ1TBsaova4M9c+bWkt7IzYHeHJLmbr4/jxedmOsSCKUkRpVXnNB6O8ltKQx8Rgpg OlfJtd0qIKlo8RkRrFTMBrRP1eiE/EvSetEGgSWKcXAL3MLQec4JtYUJmTQdtGnGj3+y ZvUQ== X-Forwarded-Encrypted: i=1; AJvYcCVkhulFR6dOMf90flf1ssaoPI3EDwnWyEL+iE0+rEYfePQMCPjTGNxXhGo3o2aFXxc+0V0Ewn9kQ5E=@lists.php.net X-Gm-Message-State: AOJu0Ywo7TevOzg6ALM0BLsju6uhiy9K8jA8qh1WKIlLjmJwQjoyYTQy sGbfl0Iyf35xD04onICMAaxdeSylzVNHERnqQPXK2CBLx+GidAnoc1odjctnqfztRJyIimRCMZS 4RvsnGBPrAntYSLDj+6HJZ4vnpKAEkss= X-Gm-Gg: ATEYQzyHlK4nBv4pVAVrRSTswMio7EIKWSmYNjs7XN7lp8ynyin9ZnTiiP49zVhdwNU Ms9z7eBrJ9+VD4XtOQvTfs5PzHU4XoZzIdcNRgDBo3R1ZSdABiMnDSVW6w1w05kkb6zUj0m+NAR 7UkyHB2xla9cxZbNTHIzza/jBk2CqVaad4O/VGZo+U+DzpDT9Rz6cxj7jdKtYyAq9P6weHDAwzd OIjlu8sqt7FH6eTO5l8unwfpYRz82jSYsam84NnDWLKWSx/N9gu3QdAgrZzq2RsYGpWTVEjSm1R DSnE+g== X-Received: by 2002:a05:6820:16a2:b0:67d:95bf:b535 with SMTP id 006d021491bc7-67e1845cdd6mr5108329eaf.0.1774808760643; Sun, 29 Mar 2026 11:26:00 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 29 Mar 2026 20:25:49 +0200 X-Gm-Features: AQROBzDIXgE9uOziENKAFnpyKuZEfYsbX2x7YTF27oGGbixgTZAiPlnnlhy9TD8 Message-ID: Subject: Re: [PHP-DEV] Re: [RFC] Stream Error Handling Improvements To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: Nicolas Grekas , PHP internals list Content-Type: multipart/alternative; boundary="000000000000b8f5d7064e2ddd9c" From: bukka@php.net (Jakub Zelenka) --000000000000b8f5d7064e2ddd9c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Thu, Mar 26, 2026 at 5:57=E2=80=AFPM Tim D=C3=BCsterhus wrote: > Hi > > thank you for your RFC. I'm regretfully late to the party, but my > primary comment about the RFC relates to the latest changes. > Specifically: > > Am 2026-02-27 23:21, schrieb Jakub Zelenka: > > I changed it to the StreamError class constants and also move the > > is*Error > > functions there. > > The RFC specifically defines =E2=80=9Cranges=E2=80=9D for the numeric val= ue of the error > constants, some of which are quite small with only 10 values available. > I believe this is dangerous, because it is possible to run out of values > within a specific range and users might make assumptions based on the > ranges when they really should rely on the `is*()` methods to check what > type of error there is. This is not a problem that would exist if the > error code was an unbacked enum. > > Contrary to Nicolas, I also don't think it is a problem for the error > code enum to be extended in future PHP versions. In other programming > languages, Rust specifically, it is also common for errors to be defined > as an enum that is explicitly defined to not be exhaustive. Here's an > example in the standard library: > https://doc.rust-lang.org/std/io/enum.ErrorKind.html. Note how the > documentation says: > > I agree with this and as you pointed out privately we already have precedent in URI extension - enum UrlValidationErrorType: https://github.com/php/php-src/blob/5e45c17d817df003cd24109f0ae222c5d82fecd= 1/ext/uri/php_uri.stub.php#L112-L143 . The constant were also not user friendly as they were just numbers so we would need some look up function to produce name. Especially painful for logging which is probably the main use case here. I changed it back to enum and this time I made it non backed which was possible to do in a nicer way due to recent changes that Arnaud did for declaration headers containing C enums. It makes the whole implementation much nicer actually. I just extended the gen_stub.php to optionally produce look up table for enum name which should speed up and simplify the look ups. As for the `StreamError` class being a linked list: I agree with the > folks that mentioned that the returned errors should be an array > instead. `count()` would naturally be available, `hasCode()` can be > implemented with `array_any($errors, fn ($error) =3D> $error->code =3D=3D= =3D > CODE_DECODING_FAILED)` and the =E2=80=9Cprimary error=E2=80=9D can be obt= ained with > `array_first()` (which we added in PHP 8.5). > > As you were the second person to ask for it and that linked list was not really a PHP thing, I changed it as suggested. This changed API in more places to accommodate for it but think for logging and other use cases, it will be a bit nicer at the end. > For the naming of `stream_get_last_error()`: Within PHP we have both > `X_get_last_error()` and `X_last_error()`. The latter seems to be more > common and also what I would prefer here, because the `stream_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. > > Good 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. The RFC and the implementation is updated so please take a look! Kind regards, Jakub --000000000000b8f5d7064e2ddd9c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

On Thu, Mar 26, 2026 at 5:57= =E2=80=AFPM Tim D=C3=BCsterhus <tim@= bastelstu.be> wrote:
Hi

thank you for your RFC. I'm regretfully late to the party, but my
primary comment about the RFC relates to the latest changes.
Specifically:

Am 2026-02-27 23:21, schrieb Jakub Zelenka:
> I changed it to the StreamError class constants and also move the
> is*Error
> functions there.

The RFC specifically defines =E2=80=9Cranges=E2=80=9D for the numeric value= of the error
constants, some of which are quite small with only 10 values available. I believe this is dangerous, because it is possible to run out of values within a specific range and users might make assumptions based on the
ranges when they really should rely on the `is*()` methods to check what type of error there is. This is not a problem that would exist if the
error code was an unbacked enum.

Contrary to Nicolas, I also don't think it is a problem for the error <= br> code enum to be extended in future PHP versions. In other programming
languages, Rust specifically, it is also common for errors to be defined as an enum that is explicitly defined to not be exhaustive. Here's an <= br> example in the standard library:
https://doc.rust-lang.org/std/io/enum.ErrorKind.= html. Note how the
documentation says:


I agree with this and as you pointed o= ut privately we already have precedent=C2=A0 in URI extension - enum UrlVal= idationErrorType:=C2=A0htt= ps://github.com/php/php-src/blob/5e45c17d817df003cd24109f0ae222c5d82fecd1/e= xt/uri/php_uri.stub.php#L112-L143 .

The consta= nt were also not user friendly as they were just numbers so we would need s= ome look up function to produce name. Especially painful for logging which = is probably the main use case here.

I changed it b= ack to enum and this time I made it non backed which was possible to do in = a nicer way due to recent changes that Arnaud did for declaration headers c= ontaining C enums. It makes the whole implementation much nicer actually. I= just extended the gen_stub.php to optionally produce look up table for enu= m name which should speed up and simplify the look ups.=C2=A0
As for the `StreamError` class being a linked list: I agree with the
folks that mentioned that the returned errors should be an array
instead. `count()` would naturally be available, `hasCode()` can be
implemented with `array_any($errors, fn ($error) =3D> $error->code = =3D=3D=3D
CODE_DECODING_FAILED)` and the =E2=80=9Cprimary error=E2=80=9D can be obtai= ned with
`array_first()` (which we added in PHP 8.5).


As you were the second person to ask f= or it and that linked list was not really a PHP thing, I changed it as sugg= ested. This changed API in more places to accommodate for it but think for = logging and other use cases, it will be a bit nicer at the end.
= =C2=A0
For the naming of `stream_get_last_error()`: Within PHP we have both
`X_get_last_error()` and `X_last_error()`. The latter seems to be more
common and also what I would prefer here, because the `stream_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.

Good point, I changed it but because = it now returns array (no linked list), it's called stream_last_errors()= . I also added=C2=A0=C2=A0stream_clear_errors for explicit clearing which m= ight be useful in some situations.

The RFC and the= implementation is updated so please take a look!

= Kind regards,

Jakub
--000000000000b8f5d7064e2ddd9c--