Skip to content

mb_convert_kana is broken in PHP8.2.0 #10174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
akira345 opened this issue Dec 28, 2022 · 4 comments
Closed

mb_convert_kana is broken in PHP8.2.0 #10174

akira345 opened this issue Dec 28, 2022 · 4 comments

Comments

@akira345
Copy link

Description

mb_convert_kana is broken in PHP8.2.0.
The code below works fine in PHP8.1.13, but returns Fatal error: Uncaught ValueError: mb_convert_kana(): Argument #2 ($mode) must not combine 'h' and 'k' flags in PHP8.2.0.

The following code:

<?php
$ret = mb_convert_kana("fooあいうエオ","rnaskh","UTF-8");
print($ret);

Resulted in this output:

// for PHP8.1.13
fooアイウエオ

// for PHP8.2.0
Fatal error: Uncaught ValueError: mb_convert_kana(): Argument #2 ($mode) must not combine 'h' and 'k' flags

But I expected this output instead:

// for PHP8.1.13
fooアイウエオ

// for PHP8.2.0
fooアイウエオ

PHP Version

PHP 8.2.0

Operating System

Debian GNU/Linux 11

@youkidearitai
Copy link
Contributor

Since PHP 8.2 it now does a $mode check, but hk is valid.

From mb_convert_kana's manual

  • h flag is "Convert "zen-kaku hira-gana"(ひらがな) to "han-kaku kata-kana"(カタカナ) "
  • k flag is Convert "zen-kaku kata-kana"(カタカナ) to "han-kaku kata-kana"(カタカナ) "

Therefore, hk can combine.

@cmb69
Copy link
Member

cmb69 commented Dec 28, 2022

This check has been introduced with dcaa010. @alexdowad, can you please check this issue?

@alexdowad
Copy link
Contributor

Thanks for the report. You are right that hk does indeed make sense.

Will fix ASAP.

@alexdowad
Copy link
Contributor

Any other feedback on which combinations of flags for mb_convert_kana do and do not make sense is also welcome.

We want to avoid:

  1. Combinations which are contradictory, such as HK ("convert all HW kana to FW hiragana" but also "convert all HW kana to FW katakana").
  2. Combinations which would make mb_convert_kana convert X to Y and then Y back to X again, such as "convert all HW kana to FW kana" but also "convert all FW kana to HW kana".

alexdowad added a commit to alexdowad/php-src that referenced this issue Dec 28, 2022
The 'h' flag makes mb_convert_kana convert zenkaku hiragana to hankaku
katakana; 'k' makes it convert zenkaku katakana to hankaku katakana.

When working on the implementation of mb_convert_kana, I added some
additional checks to catch combinations of flags which do not make
sense; but there is no conflict between 'h' and 'k' (they control
conversions for two disjoint ranges of codepoints) and this combination
should not have been restricted.

Thanks to the GitHub user 'akira345' for reporting this problem.

Closes phpGH-10174.
alexdowad added a commit to alexdowad/php-src that referenced this issue Dec 29, 2022
The 'h' flag makes mb_convert_kana convert zenkaku hiragana to hankaku
katakana; 'k' makes it convert zenkaku katakana to hankaku katakana.

When working on the implementation of mb_convert_kana, I added some
additional checks to catch combinations of flags which do not make
sense; but there is no conflict between 'h' and 'k' (they control
conversions for two disjoint ranges of codepoints) and this combination
should not have been restricted.

Thanks to the GitHub user 'akira345' for reporting this problem.

Closes phpGH-10174.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants