3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ColorCLI { static $foreground_colors = array( 'bold' => '1', 'dim' => '2', 'black' => '0;30', 'dark_gray' => '1;30', 'blue' => '0;34', 'light_blue' => '1;34', 'green' => '0;32', 'light_green' => '1;32', 'cyan' => '0;36', 'light_cyan' => '1;36', 'red' => '0;31', 'light_red' => '1;31', 'purple' => '0;35', 'light_purple' => '1;35', 'brown' => '0;33', 'yellow' => '1;33', 'light_gray' => '0;37', 'white' => '1;37', 'normal' => '0;39', ); static $background_colors = array( 'black' => '40', 'red' => '41', 'green' => '42', 'yellow' => '43', 'blue' => '44', 'magenta' => '45', 'cyan' => '46', 'light_gray' => '47', ); static $options = array( 'underline' => '4', 'blink' => '5', 'reverse' => '7', 'hidden' => '8', ); public static function __callStatic( $foreground_color, $args ) { $string = $args[0]; $colored_string = ""; // Check if given foreground color found if( isset(self::$foreground_colors[$foreground_color]) ) { $colored_string .= "\033[" . self::$foreground_colors[$foreground_color] . "m"; }else{ die( $foreground_color . ' not a valid color'); } array_shift($args); foreach( $args as $option ){ // Check if given background color found if(isset(self::$background_colors[$option])) { $colored_string .= "\033[" . self::$background_colors[$option] . "m"; }elseif(isset(self::$options[$option])) { $colored_string .= "\033[" . self::$options[$option] . "m"; } } // Add string and end coloring $colored_string .= $string . "\033[0m"; return $colored_string; } public static function bell($count = 1) { echo str_repeat("\007", $count); } } echo ColorCLI.red("text");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mA3kf
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   FETCH_CONSTANT                                   ~0      'ColorCLI'
          1        INIT_FCALL_BY_NAME                                       'red'
          2        SEND_VAL_EX                                              'text'
          3        DO_FCALL                                      0  $1      
          4        CONCAT                                           ~2      ~0, $1
          5        ECHO                                                     ~2
          6      > RETURN                                                   1

Class ColorCLI:
Function __callstatic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 39
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 39
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 38
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 14
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/mA3kf
function name:  __callStatic
number of ops:  44
compiled vars:  !0 = $foreground_color, !1 = $args, !2 = $string, !3 = $colored_string, !4 = $option
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        FETCH_DIM_R                                      ~5      !1, 0
          3        ASSIGN                                                   !2, ~5
   31     4        ASSIGN                                                   !3, ''
   34     5        FETCH_STATIC_PROP_IS                             ~8      'foreground_colors'
          6        ISSET_ISEMPTY_DIM_OBJ                         0          ~8, !0
          7      > JMPZ                                                     ~9, ->14
   35     8    >   FETCH_STATIC_PROP_R          unknown             ~10     'foreground_colors'
          9        FETCH_DIM_R                                      ~11     ~10, !0
         10        CONCAT                                           ~12     '%1B%5B', ~11
         11        CONCAT                                           ~13     ~12, 'm'
         12        ASSIGN_OP                                     8          !3, ~13
         13      > JMP                                                      ->16
   37    14    >   CONCAT                                           ~15     !0, '+not+a+valid+color'
         15      > EXIT                                                     ~15
   39    16    >   INIT_FCALL                                               'array_shift'
         17        SEND_REF                                                 !1
         18        DO_ICALL                                                 
   40    19      > FE_RESET_R                                       $17     !1, ->39
         20    > > FE_FETCH_R                                               $17, !4, ->39
   42    21    >   FETCH_STATIC_PROP_IS                             ~18     'background_colors'
         22        ISSET_ISEMPTY_DIM_OBJ                         0          ~18, !4
         23      > JMPZ                                                     ~19, ->30
   43    24    >   FETCH_STATIC_PROP_R          unknown             ~20     'background_colors'
         25        FETCH_DIM_R                                      ~21     ~20, !4
         26        CONCAT                                           ~22     '%1B%5B', ~21
         27        CONCAT                                           ~23     ~22, 'm'
         28        ASSIGN_OP                                     8          !3, ~23
         29      > JMP                                                      ->38
   44    30    >   FETCH_STATIC_PROP_IS                             ~25     'options'
         31        ISSET_ISEMPTY_DIM_OBJ                         0          ~25, !4
         32      > JMPZ                                                     ~26, ->38
   45    33    >   FETCH_STATIC_PROP_R          unknown             ~27     'options'
         34        FETCH_DIM_R                                      ~28     ~27, !4
         35        CONCAT                                           ~29     '%1B%5B', ~28
         36        CONCAT                                           ~30     ~29, 'm'
         37        ASSIGN_OP                                     8          !3, ~30
   40    38    > > JMP                                                      ->20
         39    >   FE_FREE                                                  $17
   49    40        CONCAT                                           ~32     !2, '%1B%5B0m'
         41        ASSIGN_OP                                     8          !3, ~32
   50    42      > RETURN                                                   !3
   51    43*     > RETURN                                                   null

End of function __callstatic

Function bell:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mA3kf
function name:  bell
number of ops:  7
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV_INIT                                        !0      1
   54     1        INIT_FCALL                                               'str_repeat'
          2        SEND_VAL                                                 '%07'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        ECHO                                                     $1
   55     6      > RETURN                                                   null

End of function bell

End of class ColorCLI.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.38 ms | 1392 KiB | 17 Q