3v4l.org

run code in 300+ PHP versions simultaneously
<?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; } }
Output for git.master, git.master_jit
======================= Input NULL Original output string(4) "null" Patch Peter output string(2) "[]" *** BC-break detected in patch!! *** Patch Sergey output string(2) """" *** BC-break detected in patch!! *** Patch 1 Juliette output string(2) "[]" *** BC-break detected in patch!! *** Patch 2 Juliette output string(4) "null" ======================= Input bool(false) Original output string(4) "[""]" Patch Peter output string(4) "[""]" Patch Sergey output string(2) """" *** BC-break detected in patch!! *** Patch 1 Juliette output string(4) "[""]" Patch 2 Juliette output string(4) "[""]" ======================= Input int(1) Fatal error: Uncaught Error: Cannot use a scalar value as an array in /in/ODNk5:28 Stack trace: #0 {main} thrown in /in/ODNk5 on line 28
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
12.84 ms | 460 KiB | 5 Q