3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); const PI_NAME = 'Число Пи'; const E_NAME = 'Число Эйлера'; final class Interpolator { public function __construct( private string $format = '%s' ) { } public function __invoke(mixed $value): string { return sprintf($this->format, $value); } } $sprintfString = sprintf( <<<'JSON' [ { "value": "%s", "name": "%s" }, { "value": "%s", "name": "%s" } ] JSON, pi(), PI_NAME, M_E, E_NAME, ); $intrp = new Interpolator(); $intrpString = <<<JSON [ { "value": "{$intrp(pi())}", "name": "{$intrp(PI_NAME)}" }, { "value": "{$intrp(M_E)}", "name": "{$intrp(E_NAME)}" } ] JSON; var_dump(assert($sprintfString === $intrpString));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DogHB
function name:  (null)
number of ops:  53
compiled vars:  !0 = $sprintfString, !1 = $intrp, !2 = $intrpString
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DECLARE_CONST                                            'PI_NAME', '%D0%A7%D0%B8%D1%81%D0%BB%D0%BE+%D0%9F%D0%B8'
    6     1        DECLARE_CONST                                            'E_NAME', '%D0%A7%D0%B8%D1%81%D0%BB%D0%BE+%D0%AD%D0%B9%D0%BB%D0%B5%D1%80%D0%B0'
   21     2        INIT_FCALL                                               'sprintf'
   23     3        SEND_VAL                                                 '%5B%0A++%7B+%22value%22%3A+%22%25s%22%2C+%22name%22%3A+%22%25s%22+%7D%2C%0A++%7B+%22value%22%3A+%22%25s%22%2C+%22name%22%3A+%22%25s%22+%7D%0A%5D'
   28     4        INIT_FCALL                                               'pi'
          5        DO_ICALL                                         $3      
          6        SEND_VAR                                                 $3
   29     7        FETCH_CONSTANT                                   ~4      'PI_NAME'
          8        SEND_VAL                                                 ~4
   30     9        SEND_VAL                                                 2.71828
   31    10        FETCH_CONSTANT                                   ~5      'E_NAME'
         11        SEND_VAL                                                 ~5
   21    12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !0, $6
   34    14        NEW                                              $8      'Interpolator'
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !1, $8
   37    17        ROPE_INIT                                     9  ~19     '%5B%0A++%7B+%22value%22%3A+%22'
   38    18        INIT_DYNAMIC_CALL                                        !1
         19        INIT_FCALL                                               'pi'
         20        DO_ICALL                                         $11     
         21        SEND_VAR_NO_REF_EX                                       $11
         22        DO_FCALL                                      0  $12     
         23        ROPE_ADD                                      1  ~19     ~19, $12
         24        ROPE_ADD                                      2  ~19     ~19, '%22%2C+%22name%22%3A+%22'
         25        INIT_DYNAMIC_CALL                                        !1
         26        FETCH_CONSTANT                                   ~13     'PI_NAME'
         27        SEND_VAL_EX                                              ~13
         28        DO_FCALL                                      0  $14     
         29        ROPE_ADD                                      3  ~19     ~19, $14
         30        ROPE_ADD                                      4  ~19     ~19, '%22+%7D%2C%0A++%7B+%22value%22%3A+%22'
   39    31        INIT_DYNAMIC_CALL                                        !1
         32        SEND_VAL_EX                                              2.71828
         33        DO_FCALL                                      0  $15     
         34        ROPE_ADD                                      5  ~19     ~19, $15
         35        ROPE_ADD                                      6  ~19     ~19, '%22%2C+%22name%22%3A+%22'
         36        INIT_DYNAMIC_CALL                                        !1
         37        FETCH_CONSTANT                                   ~16     'E_NAME'
         38        SEND_VAL_EX                                              ~16
         39        DO_FCALL                                      0  $17     
         40        ROPE_ADD                                      7  ~19     ~19, $17
         41        ROPE_END                                      8  ~18     ~19, '%22+%7D%0A%5D'
   36    42        ASSIGN                                                   !2, ~18
   43    43        INIT_FCALL                                               'var_dump'
         44        ASSERT_CHECK                                     $26     
         45        INIT_FCALL                                               'assert'
         46        IS_IDENTICAL                                     ~25     !0, !2
         47        SEND_VAL                                                 ~25
         48        SEND_VAL                                                 'assert%28%24sprintfString+%3D%3D%3D+%24intrpString%29'
         49        DO_ICALL                                         $26     
         50        SEND_VAR                                                 $26
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Class Interpolator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DogHB
function name:  __construct
number of ops:  4
compiled vars:  !0 = $format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV_INIT                                        !0      '%25s'
          1        ASSIGN_OBJ                                               'format'
          2        OP_DATA                                                  !0
   13     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DogHB
function name:  __invoke
number of ops:  10
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'sprintf'
          2        FETCH_OBJ_R                                      ~1      'format'
          3        SEND_VAL                                                 ~1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   18     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function __invoke

End of class Interpolator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.35 ms | 1006 KiB | 17 Q