Automattic\WooCommerce\Internal\Admin\Settings

SettingsUISchema::to_canonical_stringprivate staticWC 1.0

Cast a scalar to the string the client's String() coercion produces, so canonicalizing a value never changes which option or visibility rule it matches. PHP casts diverge from String() for booleans: (string) true is '1' and (string) false is '', while String() gives 'true' and 'false'. Floats convert through wc_float_to_string() because a plain cast is locale-sensitive before PHP 8.0 and String() never emits a comma.

Method of the class: SettingsUISchema{}

No Hooks.

Returns

String.

Usage

$result = SettingsUISchema::to_canonical_string( $value ): string;
$value(true|false|int|float|string) (required)
Scalar value.

SettingsUISchema::to_canonical_string() code WC 11.0.1

private static function to_canonical_string( $value ): string {
	if ( is_bool( $value ) ) {
		return $value ? 'true' : 'false';
	}

	if ( is_float( $value ) ) {
		return wc_float_to_string( $value );
	}

	return (string) $value;
}