3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thesaurus { protected $synonyms = array( array('wonderful', 'great', 'amazing', 'fabulous'), array('look', 'see', 'observe') ); public function replace($word) { foreach ($this->synonyms as $synonym) { if (in_array($word, $synonym)) { return $synonym[ array_rand($synonym) ]; } } return $word; } } $thesaurus = new Thesaurus; $description = 'This is my wonderful description. It really is wonderful. Look how wonderful it is.'; foreach (str_word_count($description) as $word) { $description = str_replace($word, $thesaurus->replace($word), $description); } echo $description, PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/8rRfs
function name:  (null)
number of ops:  23
compiled vars:  !0 = $thesaurus, !1 = $description, !2 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $3      'Thesaurus'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   20     3        ASSIGN                                                   !1, 'This+is+my+wonderful+description.+It+really+is+wonderful.+Look+how+wonderful+it+is.'
   22     4        INIT_FCALL                                               'str_word_count'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7      > FE_RESET_R                                       $8      $7, ->19
          8    > > FE_FETCH_R                                               $8, !2, ->19
   23     9    >   INIT_FCALL                                               'str_replace'
         10        SEND_VAR                                                 !2
         11        INIT_METHOD_CALL                                         !0, 'replace'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR                                                 $9
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !1, $10
   22    18      > JMP                                                      ->8
         19    >   FE_FREE                                                  $8
   26    20        ECHO                                                     !1
         21        ECHO                                                     '%0A'
         22      > RETURN                                                   1

Class Thesaurus:
Function replace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/8rRfs
function name:  replace
number of ops:  19
compiled vars:  !0 = $word, !1 = $synonym
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FETCH_OBJ_R                                      ~2      'synonyms'
          2      > FE_RESET_R                                       $3      ~2, ->16
          3    > > FE_FETCH_R                                               $3, !1, ->16
   11     4    >   INIT_FCALL                                               'in_array'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8      > JMPZ                                                     $4, ->15
   12     9    >   INIT_FCALL                                               'array_rand'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $5      
         12        FETCH_DIM_R                                      ~6      !1, $5
         13        FE_FREE                                                  $3
         14      > RETURN                                                   ~6
   10    15    > > JMP                                                      ->3
         16    >   FE_FREE                                                  $3
   15    17      > RETURN                                                   !0
   16    18*     > RETURN                                                   null

End of function replace

End of class Thesaurus.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.31 ms | 1400 KiB | 21 Q