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, 1) 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 = 9, Position 2 = 20
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/Jqf5b
function name:  (null)
number of ops:  24
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        SEND_VAL                                                 1
          7        DO_ICALL                                         $7      
          8      > FE_RESET_R                                       $8      $7, ->20
          9    > > FE_FETCH_R                                               $8, !2, ->20
   23    10    >   INIT_FCALL                                               'str_replace'
         11        SEND_VAR                                                 !2
         12        INIT_METHOD_CALL                                         !0, 'replace'
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $9      
         15        SEND_VAR                                                 $9
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $10     
         18        ASSIGN                                                   !1, $10
   22    19      > JMP                                                      ->9
         20    >   FE_FREE                                                  $8
   26    21        ECHO                                                     !1
         22        ECHO                                                     '%0A'
         23      > 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/Jqf5b
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:
146.96 ms | 1400 KiB | 21 Q