3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AuxiliaryVerbQuestion { private $iHaveNoClue = [ 'Why do you think I can answer that?', 'Why are you asking me?', 'Try asking @Danack', 'What are you even saying?', 'Why do you even care?', 'Who the hell are you?', 'Why are you asking?', 'You know I\'m a bot, right?', 'Wanna buy some weed?', 'WHAT YEAR IS IT??????', 'Wanna get high?', 'Who am I?', '42.', ]; private $singleOption = [ 'Possibly?', 'Probably?', 'Maybe?', 'No!!!!!!111one', 'Yes!!!!!!111one', 'No.', 'Yes.', 'Nope.', 'Yep.', 'I don\'t think so...', 'I think so...', 'Negative.', 'Affirmative.', 'Definitely no! ...right?', 'Definitely yes! ...right?', 'Granted.', 'Indeed.', ]; private $twoOptions = [ 'I\'m gonna say the former.', 'I\'m gonna say the latter.', ]; private $severalOptions = [ 'I\'d say %%%', ]; function __construct(){ $this->singleOption = array_merge($this->singleOption, $this->iHaveNoClue); } function answer($question){ echo $question . " \n"; $verbs = 'is|are|can|could|do|does|have|has|may|might|shall|should|will|would'; preg_match('@^ (' . $verbs . ') \s+ (.+?) \s+ (.+) \s* ? \s*$@x', $question, $matches); list(, $verb, $who, $options) = $matches; $options = explode("or", $options); foreach($options as $i => $option){ $options[$i] = trim($option); } if(count($options) === 1){ $answers = $this->singleOption; }else{ $answers = $this->severalOptions; if(count($options) === 2){ $answers = array_merge($answers, $this->twoOptions); } } return $answers[random_int(0, count($answers) - 1)]; } } $x = new AuxiliaryVerbQuestion(); print_r($x->answer('is @PeeHaa skynet?')); echo "\n\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GHHkb
function name:  (null)
number of ops:  11
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   NEW                                              $1      'AuxiliaryVerbQuestion'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   77     3        INIT_FCALL                                               'print_r'
          4        INIT_METHOD_CALL                                         !0, 'answer'
          5        SEND_VAL_EX                                              'is+%40PeeHaa+skynet%3F'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   78     9        ECHO                                                     '%0A%0A'
         10      > RETURN                                                   1

Class AuxiliaryVerbQuestion:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GHHkb
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   INIT_FCALL                                               'array_merge'
          1        FETCH_OBJ_R                                      ~1      'singleOption'
          2        SEND_VAL                                                 ~1
          3        FETCH_OBJ_R                                      ~2      'iHaveNoClue'
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN_OBJ                                               'singleOption'
          7        OP_DATA                                                  $3
   49     8      > RETURN                                                   null

End of function __construct

Function answer:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 51
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 33
filename:       /in/GHHkb
function name:  answer
number of ops:  60
compiled vars:  !0 = $question, !1 = $verbs, !2 = $matches, !3 = $verb, !4 = $who, !5 = $options, !6 = $option, !7 = $i, !8 = $answers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   52     1        CONCAT                                           ~9      !0, '+%0A'
          2        ECHO                                                     ~9
   53     3        ASSIGN                                                   !1, 'is%7Care%7Ccan%7Ccould%7Cdo%7Cdoes%7Chave%7Chas%7Cmay%7Cmight%7Cshall%7Cshould%7Cwill%7Cwould'
   54     4        INIT_FCALL                                               'preg_match'
          5        CONCAT                                           ~11     '%40%5E+%28', !1
          6        CONCAT                                           ~12     ~11, '%29+%5Cs%2B+%28.%2B%3F%29+%5Cs%2B+%28.%2B%29+%5Cs%2A+%3F+%5Cs%2A%24%40x'
          7        SEND_VAL                                                 ~12
          8        SEND_VAR                                                 !0
          9        SEND_REF                                                 !2
         10        DO_ICALL                                                 
   55    11        QM_ASSIGN                                        ~14     !2
         12        FETCH_LIST_R                                     $15     ~14, 1
         13        ASSIGN                                                   !3, $15
         14        FETCH_LIST_R                                     $17     ~14, 2
         15        ASSIGN                                                   !4, $17
         16        FETCH_LIST_R                                     $19     ~14, 3
         17        ASSIGN                                                   !5, $19
         18        FREE                                                     ~14
   56    19        INIT_FCALL                                               'explode'
         20        SEND_VAL                                                 'or'
         21        SEND_VAR                                                 !5
         22        DO_ICALL                                         $21     
         23        ASSIGN                                                   !5, $21
   57    24      > FE_RESET_R                                       $23     !5, ->33
         25    > > FE_FETCH_R                                       ~24     $23, !6, ->33
         26    >   ASSIGN                                                   !7, ~24
   58    27        INIT_FCALL                                               'trim'
         28        SEND_VAR                                                 !6
         29        DO_ICALL                                         $27     
         30        ASSIGN_DIM                                               !5, !7
         31        OP_DATA                                                  $27
   57    32      > JMP                                                      ->25
         33    >   FE_FREE                                                  $23
   61    34        COUNT                                            ~28     !5
         35        IS_IDENTICAL                                             ~28, 1
         36      > JMPZ                                                     ~29, ->40
   62    37    >   FETCH_OBJ_R                                      ~30     'singleOption'
         38        ASSIGN                                                   !8, ~30
   61    39      > JMP                                                      ->51
   64    40    >   FETCH_OBJ_R                                      ~32     'severalOptions'
         41        ASSIGN                                                   !8, ~32
   65    42        COUNT                                            ~34     !5
         43        IS_IDENTICAL                                             ~34, 2
         44      > JMPZ                                                     ~35, ->51
   66    45    >   INIT_FCALL                                               'array_merge'
         46        SEND_VAR                                                 !8
         47        FETCH_OBJ_R                                      ~36     'twoOptions'
         48        SEND_VAL                                                 ~36
         49        DO_ICALL                                         $37     
         50        ASSIGN                                                   !8, $37
   70    51    >   INIT_FCALL                                               'random_int'
         52        SEND_VAL                                                 0
         53        COUNT                                            ~39     !8
         54        SUB                                              ~40     ~39, 1
         55        SEND_VAL                                                 ~40
         56        DO_ICALL                                         $41     
         57        FETCH_DIM_R                                      ~42     !8, $41
         58      > RETURN                                                   ~42
   71    59*     > RETURN                                                   null

End of function answer

End of class AuxiliaryVerbQuestion.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.92 ms | 1012 KiB | 19 Q