Skip to content

Replace strict ?int type hint with string|int|null union type for get_permalink() $original_id parameter#568

Closed
Copilot wants to merge 4 commits intotrunkfrom
copilot/fix-type-error-gp-route-translation-helpers
Closed

Replace strict ?int type hint with string|int|null union type for get_permalink() $original_id parameter#568
Copilot wants to merge 4 commits intotrunkfrom
copilot/fix-type-error-gp-route-translation-helpers

Conversation

Copy link

Copilot AI commented Mar 20, 2026

GP_Route_Translation_Helpers::get_permalink() declares ?int $original_id but multiple callers pass strings — taxonomy term slugs from get_original_from_post_id(), untyped route parameters, DB object properties. This causes a fatal TypeError on PHP 8+.

The parameter is only used for string concatenation ($project_path . '/' . $original_id), so the strict int type was wrong.

  • Replaced the ?int type hint with string|int|null union type (codebase targets PHP 8.1+)
  • Removed a (int) cast workaround previously added in rewrite_original_post_type_permalink()
// Before
public static function get_permalink( string $project_path, ?int $original_id, ... ): string {

// After
public static function get_permalink( string $project_path, string|int|null $original_id, ... ): string {

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

The get_original_from_post_id() method returns a taxonomy term slug (string),
which may include WordPress slug deduplication suffixes (e.g., '12363971-2').
This string was passed directly to get_permalink() which has a strict ?int
type hint for $original_id, causing a PHP fatal TypeError.

Cast $original_id to (int) after the falsy check to ensure type compatibility.

Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TypeError in GP_Route_Translation_Helpers get_permalink method Fix TypeError in get_permalink: cast taxonomy slug to int Mar 20, 2026
Copilot AI requested a review from dd32 March 20, 2026 09:02
Copilot finished work on behalf of dd32 March 20, 2026 09:02
… parameter

The `get_permalink()` method only uses `$original_id` for string concatenation,
so the strict `?int` type hint was unnecessarily restrictive. Multiple callers
naturally pass string values (taxonomy term slugs, untyped route parameters,
DB object properties).

Remove the type hint entirely (keeping PHPDoc as `string|int|null`) to be
consistent with the rest of the codebase which uses `?type` nullable syntax
rather than PHP 8.0+ union types. Also revert the previous `(int)` cast
workaround in helper-translation-discussion.php since it's no longer needed.

Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copilot AI changed the title Fix TypeError in get_permalink: cast taxonomy slug to int Remove strict ?int type hint from get_permalink() $original_id parameter Mar 20, 2026
Copilot finished work on behalf of dd32 March 20, 2026 09:09
@dd32 dd32 marked this pull request as ready for review March 20, 2026 09:21
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @copilot.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dd32.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@dd32 dd32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but @copilot we target PHP 8.1+ at present, so if there's a cleaner way here...

@dd32
Copy link
Member

dd32 commented Mar 20, 2026

@copilot ? Follow up on above?

…s PHP 8.1+

Co-authored-by: dd32 <767313+dd32@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 20, 2026

@copilot ? Follow up on above?

Updated in 4281a90 to use the string|int|null union type now that I know the codebase targets PHP 8.1+.

Copilot AI changed the title Remove strict ?int type hint from get_permalink() $original_id parameter Replace strict ?int type hint with string|int|null union type for get_permalink() $original_id parameter Mar 20, 2026
Copilot AI requested a review from dd32 March 20, 2026 09:47
Copilot finished work on behalf of dd32 March 20, 2026 09:47
@bazza bazza closed this Mar 20, 2026
@bazza bazza deleted the copilot/fix-type-error-gp-route-translation-helpers branch March 20, 2026 13:17
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