3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $pos = 0; public $str; public function __construct($str) { $this->str = $str; $this->current = $this->lookAhead(); } function isLineBreak() { if ("\r" !== $this->current && "\n" !== $this->current) { return false; } $char = $this->current; do { $brk = ("\n" === $char); $char = $this->lookAhead(); switch ($char) { case " ": return false; case "\n": if ($brk) { return true; } break; default: return $brk; } } while (true); } function lookAhead() { return mb_strcut($this->str, $this->pos++, 1); } } function crlf($str) { $foo = new Foo($str); return $foo->isLineBreak(); } var_dump(crlf("\r\n"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9TLCR
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'crlf'
          2        SEND_VAL                                                 '%0D%0A'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function crlf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9TLCR
function name:  crlf
number of ops:  9
compiled vars:  !0 = $str, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        NEW                                              $2      'Foo'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   44     5        INIT_METHOD_CALL                                         !1, 'isLineBreak'
          6        DO_FCALL                                      0  $5      
          7      > RETURN                                                   $5
   45     8*     > RETURN                                                   null

End of function crlf

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9TLCR
function name:  __construct
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN_OBJ                                               'str'
          2        OP_DATA                                                  !0
   10     3        INIT_METHOD_CALL                                         'lookAhead'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_OBJ                                               'current'
          6        OP_DATA                                                  $3
   11     7      > RETURN                                                   null

End of function __construct

Function islinebreak:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
4 jumps found. (Code = 188) Position 1 = 21, Position 2 = 22, Position 3 = 25, Position 4 = 16
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 10
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 22
Branch analysis from position: 21
Branch analysis from position: 6
filename:       /in/9TLCR
function name:  isLineBreak
number of ops:  28
compiled vars:  !0 = $char, !1 = $brk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~2      'current'
          1        IS_NOT_IDENTICAL                                 ~3      ~2, '%0D'
          2      > JMPZ_EX                                          ~3      ~3, ->6
          3    >   FETCH_OBJ_R                                      ~4      'current'
          4        IS_NOT_IDENTICAL                                 ~5      ~4, '%0A'
          5        BOOL                                             ~3      ~5
          6    > > JMPZ                                                     ~3, ->8
   15     7    > > RETURN                                                   <false>
   18     8    >   FETCH_OBJ_R                                      ~6      'current'
          9        ASSIGN                                                   !0, ~6
   20    10    >   IS_IDENTICAL                                     ~8      !0, '%0A'
         11        ASSIGN                                                   !1, ~8
   21    12        INIT_METHOD_CALL                                         'lookAhead'
         13        DO_FCALL                                      0  $10     
         14        ASSIGN                                                   !0, $10
   22    15      > SWITCH_STRING                                            !0, [ '+':->21, '%0A':->22, ], ->25
   23    16    >   IS_EQUAL                                                 !0, '+'
         17      > JMPNZ                                                    ~12, ->21
   25    18    >   IS_EQUAL                                                 !0, '%0A'
         19      > JMPNZ                                                    ~12, ->22
         20    > > JMP                                                      ->25
   24    21    > > RETURN                                                   <false>
   26    22    > > JMPZ                                                     !1, ->24
   27    23    > > RETURN                                                   <true>
   29    24    > > JMP                                                      ->26
   31    25    > > RETURN                                                   !1
   33    26    > > JMPNZ                                                    <true>, ->10
   34    27    > > RETURN                                                   null

End of function islinebreak

Function lookahead:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9TLCR
function name:  lookAhead
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'mb_strcut'
          1        FETCH_OBJ_R                                      ~0      'str'
          2        SEND_VAL                                                 ~0
          3        POST_INC_OBJ                                     ~1      'pos'
          4        SEND_VAL                                                 ~1
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   38     8*     > RETURN                                                   null

End of function lookahead

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.89 ms | 1407 KiB | 18 Q