Skip to content

4.x: Fix PHP 7.4+ and 8.5 deprecation warnings - #310

Open
bealinawaz wants to merge 1 commit into
php-gettext:4.xfrom
bealinawaz:fix/4x-php-deprecations
Open

bealinawaz wants to merge 1 commit into
php-gettext:4.xfrom
bealinawaz:fix/4x-php-deprecations

Conversation

@bealinawaz

Copy link
Copy Markdown

The 4.x line is still used by WP-CLI's i18n command (gettext/gettext ^4.8), and on current PHP versions wp i18n make-pot prints these deprecations from it:

Deprecated: Non-canonical cast (boolean) is deprecated, use the (bool) cast instead in src/Merge.php on line 124
Deprecated: Invalid characters passed for attempted conversion, these have been ignored in src/Extractors/PhpCode.php on line 130
Deprecated: chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value must be in the [0, 255] interval. The value used will be constrained using % 256 in src/Extractors/PhpCode.php on line 132
  • Merge.php: (boolean) is deprecated in PHP 8.5; (bool) is identical.
  • PhpCode.php, \u{...} escapes: hexdec() was given the braces too ({1f600}). PHP ignored them, so the value was right, but it has warned since PHP 7.4. WordPress core triggers this on make-pot (e.g. "\u{2022}" and "\u{FFFD}" in wp-includes).
  • PhpCode.php, octal escapes \400–\777: chr() wrapped values above 255, which PHP 8.5 deprecates. % 256 gives the same byte, which also matches PHP's own "\400" === "\0".

The output is unchanged, and the code still works on PHP 5.4. Tested on PHP 8.5.12 with WP-CLI nightly running this branch with and without the patch: make-pot on WordPress core's wp-includes (8,028 strings), on five plugins, with --merge, and update-po on a translated PO file. The generated files are byte-identical apart from the creation date, and the deprecations are gone. php -l reports nothing else in src/.

@oscarotero

Copy link
Copy Markdown
Member

Ok, thank you.
Out of curiosity, why WP-CLI's stuck on 4.x? is there any reason to don't upgrade to v5? Do you still need support for php < 7.2?

@bealinawaz

Copy link
Copy Markdown
Author

Thanks! I'm not a WP-CLI maintainer, so this is only what I can see in their repo.

No, it doesn't need PHP < 7.2 anymore: WP-CLI requires PHP 7.2.24 or newer. PHP was the reason for years (wp-cli/i18n-command#303), and once the minimum went up there was an attempt to move to v5 in wp-cli/i18n-command#443 and its follow-up #465. Both were closed without merging in December 2025. #443 says v5 has a lot of changes and doesn't ship some things the command uses, such as Jed support and the ParsedComment class, and in #465 the tests were still failing around comment extraction.

So it's still on ^4.8, and a 4.x tag with this fix would reach WP-CLI with a plain composer update (wp-cli/i18n-command#521).

@swissspidy

Copy link
Copy Markdown
Contributor

Maintainer here 👋

Maybe it's time to attempt the migration again... Las time I tried it indeed seemed like too big of a lift, and the lack of ParsedComment meant we could no longer get a comment's line numbers.

@swissspidy

Copy link
Copy Markdown
Contributor

Quick update:

Making some progress in github.com/wp-cli/i18n-command/pull/522

Some observed bugs/blockers so far:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants