<?php
$test = [
null,
false,
1,
1.5,
'string',
['string in array without keys'],
['key' => 'string in array with keys'],
[
'multi-dim array' => 'string',
'sub-array' => [ 1, 2, 3]
],
];
foreach($test as $l10n) {
echo PHP_EOL,'=======================', PHP_EOL;
echo PHP_EOL,'Input',PHP_EOL;
var_dump($l10n);
$copy = $l10n;
foreach ( (array) $l10n as $key => $value ) {
if ( ! is_scalar( $value ) ) {
continue;
}
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
$encoded1 = json_encode( $l10n );
echo PHP_EOL,'Original output',PHP_EOL;
var_dump($encoded1);
$l10n = $copy;
if ( is_string( $l10n ) ) {
$l10n = html_entity_decode( (string) $l10n, ENT_QUOTES, 'UTF-8' );
} else {
$l10n = (array) $l10n;
foreach ( $l10n as $key => $value ) {
if ( ! is_scalar( $value ) ) {
continue;
}
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
}
$encoded2 = json_encode( $l10n );
echo PHP_EOL,'Patch Peter output',PHP_EOL;
var_dump($encoded2);
if ($encoded1 !== $encoded2) {
echo "*** BC-break detected in patch!! ***", PHP_EOL;
}
$l10n = $copy;
if ( ! is_array( $l10n ) ) {
$l10n = html_entity_decode( (string) $l10n, ENT_QUOTES, 'UTF-8' );
} else {
foreach ( $l10n as $key => $value ) {
if ( ! is_scalar( $value ) ) {
continue;
}
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
}
$encoded3 = json_encode( $l10n );
echo PHP_EOL,'Patch Sergey output',PHP_EOL;
var_dump($encoded3);
if ($encoded1 !== $encoded3) {
echo "*** BC-break detected in patch!! ***", PHP_EOL;
}
$l10n = $copy;
if ( ! is_array( $l10n ) ) {
// Throw the _doing_it_wrong_warning.
$l10n = (array) $l10n;
}
foreach ( $l10n as $key => $value ) {
if ( ! is_scalar( $value ) ) {
continue;
}
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
$encoded4 = json_encode( $l10n );
echo PHP_EOL,'Patch 1 Juliette output',PHP_EOL;
var_dump($encoded4);
if ($encoded1 !== $encoded4) {
echo "*** BC-break detected in patch!! ***", PHP_EOL;
}
$l10n = $copy;
if ( ! is_array( $l10n ) ) {
// Throw the _doing_it_wrong_warning.
}
if ( is_string( $l10n ) ) {
$l10n = html_entity_decode( (string) $l10n, ENT_QUOTES, 'UTF-8' );
} else {
foreach ( (array) $l10n as $key => $value ) {
if ( ! is_scalar( $value ) ) {
continue;
}
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
}
$encoded5 = json_encode( $l10n );
echo PHP_EOL,'Patch 2 Juliette output',PHP_EOL;
var_dump($encoded5);
if ($encoded1 !== $encoded5) {
echo "*** BC-break detected in patch!! ***", PHP_EOL;
}
}
preferences:
33.87 ms | 406 KiB | 5 Q