Make WordPress Core

Opened 10 months ago

Closed 8 months ago

Last modified 8 months ago

#59630 closed defect (bug) (fixed)

wp_json_encode(): rename parameters for parity with PHP Core

Reported by: jrf's profile jrf Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.5 Priority: normal
Severity: normal Version: 4.1
Component: General Keywords: has-patch
Focuses: coding-standards Cc:

Description

The wp_json_encode() is a wrapper for the PHP native json_encode() function with some extra safety checks.

I propose to rename the $data parameter in the wp_json_encode() function and associated functions to $value and the $options parameter to $flags for parity with the parameter names used in PHP Core (principle of least surprise).

Ref: https://www.php.net/manual/en/function.json-encode.php

Change History (5)

This ticket was mentioned in PR #5493 on WordPress/wordpress-develop by @jrf.


10 months ago
#1

  • Keywords has-patch added

The wp_json_encode() is a wrapper for the PHP native json_encode() function with some extra safety checks.

This commit renames the $data parameter in the wp_json_encode() function and associated functions to $value and the $options parameter to $flags for parity with the parameter names used in PHP Core (principle of least surprise).

Ref: https://www.php.net/manual/en/function.json-encode.php

Trac ticket: https://core.trac.wordpress.org/ticket/59630

#2 follow-up: @hellofromTonya
10 months ago

  • Version changed from trunk to 4.1

Changing the Version to 4.1.0 which introduced wp_json_encode() with these parameter names.

#3 in reply to: ↑ 2 @jrf
10 months ago

Replying to hellofromTonya:

Changing the Version to 4.1.0 which introduced wp_json_encode() with these parameter names.

Thanks @hellofromTonya !

On that note: it may well be that the parameter names at the time of introduction were in line with PHP Core.

PHP Core has renamed a lot of parameters to better names in the run up to the release of PHP 8.0 in anticipation of supporting named parameters.
It is not inconceivable that these parameters were renamed in PHP Core as part of that exercise.

#4 @SergeyBiryukov
8 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 57130:

General: Rename wp_json_encode() parameters for parity with PHP Core.

wp_json_encode() is a wrapper for the PHP native json_encode() function with some extra safety checks.

This commit renames the $data parameter in the wp_json_encode() function and associated functions to $value, and the $options parameter to $flags for parity with the parameter names used in PHP Core.

Reference: PHP Manual: json_encode().

Follow-up to [30055].

Props jrf, hellofromTonya.
Fixes #59630.

@SergeyBiryukov commented on PR #5493:


8 months ago
#5

Thanks for the PR! Merged in r57130.

Note: See TracTickets for help on using tickets.