3v4l.org

run code in 300+ PHP versions simultaneously
<?php $utf8_str = "\xf0\x9f\x92\xa9"; $ret = ''; $length = mb_strlen($utf8_str, 'UTF-8'); for ($i = 0; $i < $length; $i++) { $char = mb_substr($utf8_str, $i, 1, 'UTF-8'); $l = strlen($char); if ($l <= 3) { $ret .= $char; } elseif ($l === 4) { $ret .= self::convert_char_to_cesu8($char); }// UTF-8で5文字以上になる文字はUnicodeとして不正なので無視(除去する) } $unko = $ret; var_dump($unko); $encode = json_encode($unko); var_dump($encode);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Cannot access "self" when no class scope is active in /in/tRCEs:12 Stack trace: #0 {main} thrown in /in/tRCEs on line 12
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Cannot access self:: when no class scope is active in /in/tRCEs:12 Stack trace: #0 {main} thrown in /in/tRCEs on line 12
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Cannot access self:: when no class scope is active in /in/tRCEs on line 12
Process exited with code 255.

preferences:
292.53 ms | 402 KiB | 375 Q