3v4l.org

run code in 300+ PHP versions simultaneously
<?php $examples = array( 'Valid ASCII' => array("a", true), 'Valid 2 Octet Sequence' => array("\xc3\xb1", true), 'Invalid 2 Octet Sequence' => array("\xc3\x28", false), 'Invalid Sequence Identifier' => array("\xa0\xa1", false), 'Valid 3 Octet Sequence' => array("\xe2\x82\xa1", true), 'Invalid 3 Octet Sequence (in 2nd Octet)' => array("\xe2\x28\xa1", false), 'Invalid 3 Octet Sequence (in 3rd Octet)' => array("\xe2\x82\x28", false), 'Valid 4 Octet Sequence' => array("\xf0\x90\x8c\xbc", true), 'Invalid 4 Octet Sequence (in 2nd Octet)' => array("\xf0\x28\x8c\xbc", false), 'Invalid 4 Octet Sequence (in 3rd Octet)' => array("\xf0\x90\x28\xbc", false), 'Invalid 4 Octet Sequence (in 4th Octet)' => array("\xf0\x28\x8c\x28", false), 'Valid 5 Octet Sequence (but not Unicode!)' => array("\xf8\xa1\xa1\xa1\xa1", false), 'Valid 6 Octet Sequence (but not Unicode!)' => array("\xfc\xa1\xa1\xa1\xa1\xa1", false), ); function checkWithPreg($str) { return preg_match('//u', $str); } function checkWithMbstring($str) { return mb_check_encoding($str, 'UTF-8'); } function test($actual, $expected, $title) { echo $actual == $expected ? "[Success]" : "[Fail]"; echo " $title\n"; } function runTests($method) { global $examples; foreach($examples as $title => $arr) { list($str, $bool) = $arr; test($method($str), $bool, $title); } } runTests('checkWithPreg'); echo "\n"; runTests('checkWithMbstring');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdNpr
function name:  (null)
number of ops:  9
compiled vars:  !0 = $examples
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   35     1        INIT_FCALL                                               'runtests'
          2        SEND_VAL                                                 'checkWithPreg'
          3        DO_FCALL                                      0          
   36     4        ECHO                                                     '%0A'
   37     5        INIT_FCALL                                               'runtests'
          6        SEND_VAL                                                 'checkWithMbstring'
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function checkwithpreg:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdNpr
function name:  checkWithPreg
number of ops:  7
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%2Fu'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   19     6*     > RETURN                                                   null

End of function checkwithpreg

Function checkwithmbstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdNpr
function name:  checkWithMbstring
number of ops:  7
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'mb_check_encoding'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'UTF-8'
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   22     6*     > RETURN                                                   null

End of function checkwithmbstring

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdNpr
function name:  test
number of ops:  14
compiled vars:  !0 = $actual, !1 = $expected, !2 = $title
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   24     3        IS_EQUAL                                                 !0, !1
          4      > JMPZ                                                     ~3, ->7
          5    >   QM_ASSIGN                                        ~4      '%5BSuccess%5D'
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~4      '%5BFail%5D'
          8    >   ECHO                                                     ~4
   25     9        ROPE_INIT                                     3  ~6      '+'
         10        ROPE_ADD                                      1  ~6      ~6, !2
         11        ROPE_END                                      2  ~5      ~6, '%0A'
         12        ECHO                                                     ~5
   26    13      > RETURN                                                   null

End of function test

Function runtests:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/kdNpr
function name:  runTests
number of ops:  22
compiled vars:  !0 = $method, !1 = $examples, !2 = $arr, !3 = $title, !4 = $str, !5 = $bool
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        BIND_GLOBAL                                              !1, 'examples'
   29     2      > FE_RESET_R                                       $6      !1, ->20
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->20
          4    >   ASSIGN                                                   !3, ~7
   30     5        QM_ASSIGN                                        ~9      !2
          6        FETCH_LIST_R                                     $10     ~9, 0
          7        ASSIGN                                                   !4, $10
          8        FETCH_LIST_R                                     $12     ~9, 1
          9        ASSIGN                                                   !5, $12
         10        FREE                                                     ~9
   31    11        INIT_FCALL                                               'test'
         12        INIT_DYNAMIC_CALL                                        !0
         13        SEND_VAR_EX                                              !4
         14        DO_FCALL                                      0  $14     
         15        SEND_VAR                                                 $14
         16        SEND_VAR                                                 !5
         17        SEND_VAR                                                 !3
         18        DO_FCALL                                      0          
   29    19      > JMP                                                      ->3
         20    >   FE_FREE                                                  $6
   33    21      > RETURN                                                   null

End of function runtests

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.7 ms | 1403 KiB | 20 Q