# No longer allow block mode for declare(encoding)

- Thread: https://externals.io/message/118544
- Original archive: https://news-web.php.net/php.internals/118544
- Started by Christoph M. Becker on 2022-08-31T15:43:15+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #118544 — Christoph M. Becker — 2022-08-31T15:43:15+00:00

URL: https://externals.io/message/118544#118544

Hi all,

recently, there was a bug report regarding declare(encoding)[1].  I've
checked that, and found that the current implementation of
declare(encoding) doesn't make sense regarding "block mode", since this
is completely ignored; instead, each (allowed) declare(encoding) works
from where it is written till the next declare(encoding) (well, probably
more or less).

Since I consider switching the character encoding in the middle of a
file not reasonable (and it might be hard to properly implement support
for that), I suggest to disallow block mode for declare(encoding) as of
PHP 8.3.  A respective PR is available[2].

Thoughts?

[1] <https://github.com/php/php-src/issues/9446>
[2] <https://github.com/php/php-src/pull/9455>

--
Christoph M. Becker

---

## #118545 — Sara Golemon — 2022-08-31T19:20:51+00:00

URL: https://externals.io/message/118544#118545 · In reply to: #118544

On Wed, Aug 31, 2022 at 10:43 AM Christoph M. Becker <cmbecker69@gmx.de>
wrote:

> recently, there was a bug report regarding declare(encoding)[1].  I've
> checked that, and found that the current implementation of
> declare(encoding) doesn't make sense regarding "block mode", since this
> is completely ignored; instead, each (allowed) declare(encoding) works
> from where it is written till the next declare(encoding) (well, probably
> more or less).
>
> Since I consider switching the character encoding in the middle of a
> file not reasonable (and it might be hard to properly implement support
> for that), I suggest to disallow block mode for declare(encoding) as of
> PHP 8.3.  A respective PR is available[2].
>
>
I think I can imagine scenarios where switching encodings within a file
would.... work?  Especially for ASCII transparent encodings...  That said,
if you're currently depending on multiple encodings in a single file then
you probably deserve whatever you get.

+1

-Sara

---

## #118547 — Hans Henrik Bergan — 2022-08-31T21:13:31+00:00

URL: https://externals.io/message/118544#118547 · In reply to: #118545

>it might be hard to properly implement support

No effort should be wasted supporting this.
+1



> On Wed, Aug 31, 2022 at 10:43 AM Christoph M. Becker <cmbecker69@gmx.de>
> wrote:
>
> > […]
> I think I can imagine scenarios where switching encodings within a file
> would.... work?  Especially for ASCII transparent encodings...  That said,
> if you're currently depending on multiple encodings in a single file then
> you probably deserve whatever you get.
>
> +1
>
> -Sara
