3v4l.org

run code in 500+ 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:  55
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'
   28     2        INIT_FCALL                                                   'pi'
          3        DO_ICALL                                             $3      
   29     4        FETCH_CONSTANT                                       ~4      'PI_NAME'
   31     5        FETCH_CONSTANT                                       ~5      'E_NAME'
          6        ROPE_INIT                                         9  ~7      '%5B%0A++%7B+%22value%22%3A+%22'
          7        ROPE_ADD                                          1  ~7      ~7, $3
          8        ROPE_ADD                                          2  ~7      ~7, '%22%2C+%22name%22%3A+%22'
          9        ROPE_ADD                                          3  ~7      ~7, ~4
         10        ROPE_ADD                                          4  ~7      ~7, '%22+%7D%2C%0A++%7B+%22value%22%3A+%22'
         11        ROPE_ADD                                          5  ~7      ~7, '2.718281828459'
         12        ROPE_ADD                                          6  ~7      ~7, '%22%2C+%22name%22%3A+%22'
         13        ROPE_ADD                                          7  ~7      ~7, ~5
         14        ROPE_END                                          8  ~6      ~7, '%22+%7D%0A%5D'
   21    15        ASSIGN                                                       !0, ~6
   34    16        NEW                                                  $13     'Interpolator'
         17        DO_FCALL                                          0          
         18        ASSIGN                                                       !1, $13
   37    19        ROPE_INIT                                         9  ~24     '%5B%0A++%7B+%22value%22%3A+%22'
   38    20        INIT_DYNAMIC_CALL                                            !1
         21        INIT_FCALL                                                   'pi'
         22        DO_ICALL                                             $16     
         23        SEND_VAR_NO_REF_EX                                           $16
         24        DO_FCALL                                          0  $17     
         25        ROPE_ADD                                          1  ~24     ~24, $17
         26        ROPE_ADD                                          2  ~24     ~24, '%22%2C+%22name%22%3A+%22'
         27        INIT_DYNAMIC_CALL                                            !1
         28        FETCH_CONSTANT                                       ~18     'PI_NAME'
         29        SEND_VAL_EX                                                  ~18
         30        DO_FCALL                                          0  $19     
         31        ROPE_ADD                                          3  ~24     ~24, $19
         32        ROPE_ADD                                          4  ~24     ~24, '%22+%7D%2C%0A++%7B+%22value%22%3A+%22'
   39    33        INIT_DYNAMIC_CALL                                            !1
         34        SEND_VAL_EX                                                  2.71828
         35        DO_FCALL                                          0  $20     
         36        ROPE_ADD                                          5  ~24     ~24, $20
         37        ROPE_ADD                                          6  ~24     ~24, '%22%2C+%22name%22%3A+%22'
         38        INIT_DYNAMIC_CALL                                            !1
         39        FETCH_CONSTANT                                       ~21     'E_NAME'
         40        SEND_VAL_EX                                                  ~21
         41        DO_FCALL                                          0  $22     
         42        ROPE_ADD                                          7  ~24     ~24, $22
         43        ROPE_END                                          8  ~23     ~24, '%22+%7D%0A%5D'
   36    44        ASSIGN                                                       !2, ~23
   43    45        INIT_FCALL                                                   'var_dump'
         46        ASSERT_CHECK                                         $31     
         47        INIT_FCALL                                                   'assert'
         48        IS_IDENTICAL                                         ~30     !0, !2
         49        SEND_VAL                                                     ~30
         50        SEND_VAL                                                     'assert%28%24sprintfString+%3D%3D%3D+%24intrpString%29'
         51        DO_ICALL                                             $31     
         52        SEND_VAR                                                     $31
         53        DO_ICALL                                                     
         54      > 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
-----------------------------------------------------------------------------------------
   11     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.5.0


preferences:
127.7 ms | 486 KiB | 11 Q