3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); function get_user_meta($user_id, $key, $ingle) { return 5; } function get_curriculum($id) { return [ 1, 2, 3 ]; } class init { private $time_spent; public function __construct() { $this->time_spent = array(); } public function get_course_unit_time_spent($user_id, $course_id, $unit_id) { if (empty($this->time_spent[$course_id]) || empty($this->time_spent[$course_id][$unit_id])) { $this->time_spent[$course_id][$unit_id] = get_user_meta($user_id, 'time_spent_'.$course_id.'_'.$unit_id, true); if (empty($this->time_spent[$course_id][$unit_id])) { $this->time_spent[$course_id][$unit_id] = 0; } } return $this->time_spent[$course_id][$unit_id]; } public function get_course_time_spent($user_id, $course_id) { if (empty($this->time_spent[$course_id])) { $time_spent = 0; foreach ((array) get_curriculum($course_id) as $unit_id) { if(is_numeric($unit_id)){ $time_spent += $this->get_course_unit_time_spent($user_id, $course_id, $unit_id); } } $this->time_spent[$course_id] = $time_spent; } return $this->time_spent[$course_id]; } } $init = new init; echo $init->get_course_time_spent(1, 234).PHP_EOL; echo $init->get_course_time_spent(2, 2345).PHP_EOL; echo $init->get_course_time_spent(3, 23456).PHP_EOL; print_r($init);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ppcif
function name:  (null)
number of ops:  32
compiled vars:  !0 = $init
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
    3     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 '1'
          6        DO_ICALL                                                 
   54     7        NEW                                              $3      'init'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $3
   56    10        INIT_METHOD_CALL                                         !0, 'get_course_time_spent'
         11        SEND_VAL_EX                                              1
         12        SEND_VAL_EX                                              234
         13        DO_FCALL                                      0  $6      
         14        CONCAT                                           ~7      $6, '%0A'
         15        ECHO                                                     ~7
   57    16        INIT_METHOD_CALL                                         !0, 'get_course_time_spent'
         17        SEND_VAL_EX                                              2
         18        SEND_VAL_EX                                              2345
         19        DO_FCALL                                      0  $8      
         20        CONCAT                                           ~9      $8, '%0A'
         21        ECHO                                                     ~9
   58    22        INIT_METHOD_CALL                                         !0, 'get_course_time_spent'
         23        SEND_VAL_EX                                              3
         24        SEND_VAL_EX                                              23456
         25        DO_FCALL                                      0  $10     
         26        CONCAT                                           ~11     $10, '%0A'
         27        ECHO                                                     ~11
   60    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
   61    31      > RETURN                                                   1

Function get_user_meta:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ppcif
function name:  get_user_meta
number of ops:  5
compiled vars:  !0 = $user_id, !1 = $key, !2 = $ingle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    6     3      > RETURN                                                   5
    7     4*     > RETURN                                                   null

End of function get_user_meta

Function get_curriculum:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ppcif
function name:  get_curriculum
number of ops:  3
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1      > RETURN                                                   <array>
   13     2*     > RETURN                                                   null

End of function get_curriculum

Class init:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ppcif
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN_OBJ                                               'time_spent'
          1        OP_DATA                                                  <array>
   21     2      > RETURN                                                   null

End of function __construct

Function get_course_unit_time_spent:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 31
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 31
Branch analysis from position: 10
filename:       /in/Ppcif
function name:  get_course_unit_time_spent
number of ops:  36
compiled vars:  !0 = $user_id, !1 = $course_id, !2 = $unit_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   25     3        FETCH_OBJ_IS                                     ~3      'time_spent'
          4        ISSET_ISEMPTY_DIM_OBJ                         1  ~4      ~3, !1
          5      > JMPNZ_EX                                         ~4      ~4, ->10
          6    >   FETCH_OBJ_IS                                     ~5      'time_spent'
          7        FETCH_DIM_IS                                     ~6      ~5, !1
          8        ISSET_ISEMPTY_DIM_OBJ                         1  ~7      ~6, !2
          9        BOOL                                             ~4      ~7
         10    > > JMPZ                                                     ~4, ->31
   27    11    >   INIT_FCALL                                               'get_user_meta'
         12        SEND_VAR                                                 !0
         13        CONCAT                                           ~11     'time_spent_', !1
         14        CONCAT                                           ~12     ~11, '_'
         15        CONCAT                                           ~13     ~12, !2
         16        SEND_VAL                                                 ~13
         17        SEND_VAL                                                 <true>
         18        DO_FCALL                                      0  $14     
         19        FETCH_OBJ_W                                      $8      'time_spent'
         20        FETCH_DIM_W                                      $9      $8, !1
         21        ASSIGN_DIM                                               $9, !2
         22        OP_DATA                                                  $14
   29    23        FETCH_OBJ_IS                                     ~15     'time_spent'
         24        FETCH_DIM_IS                                     ~16     ~15, !1
         25        ISSET_ISEMPTY_DIM_OBJ                         1          ~16, !2
         26      > JMPZ                                                     ~17, ->31
   30    27    >   FETCH_OBJ_W                                      $18     'time_spent'
         28        FETCH_DIM_W                                      $19     $18, !1
         29        ASSIGN_DIM                                               $19, !2
         30        OP_DATA                                                  0
   34    31    >   FETCH_OBJ_R                                      ~21     'time_spent'
         32        FETCH_DIM_R                                      ~22     ~21, !1
         33        FETCH_DIM_R                                      ~23     ~22, !2
         34      > RETURN                                                   ~23
   35    35*     > RETURN                                                   null

End of function get_course_unit_time_spent

Function get_course_time_spent:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 27
filename:       /in/Ppcif
function name:  get_course_time_spent
number of ops:  31
compiled vars:  !0 = $user_id, !1 = $course_id, !2 = $time_spent, !3 = $unit_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        FETCH_OBJ_IS                                     ~4      'time_spent'
          3        ISSET_ISEMPTY_DIM_OBJ                         1          ~4, !1
          4      > JMPZ                                                     ~5, ->27
   40     5    >   ASSIGN                                                   !2, 0
   41     6        INIT_FCALL                                               'get_curriculum'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $7      
          9        CAST                                          7  ~8      $7
         10      > FE_RESET_R                                       $9      ~8, ->23
         11    > > FE_FETCH_R                                               $9, !3, ->23
   42    12    >   INIT_FCALL                                               'is_numeric'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                         $10     
         15      > JMPZ                                                     $10, ->22
   43    16    >   INIT_METHOD_CALL                                         'get_course_unit_time_spent'
         17        SEND_VAR_EX                                              !0
         18        SEND_VAR_EX                                              !1
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0  $11     
         21        ASSIGN_OP                                     1          !2, $11
   41    22    > > JMP                                                      ->11
         23    >   FE_FREE                                                  $9
   46    24        FETCH_OBJ_W                                      $13     'time_spent'
         25        ASSIGN_DIM                                               $13, !1
         26        OP_DATA                                                  !2
   49    27    >   FETCH_OBJ_R                                      ~15     'time_spent'
         28        FETCH_DIM_R                                      ~16     ~15, !1
         29      > RETURN                                                   ~16
   51    30*     > RETURN                                                   null

End of function get_course_time_spent

End of class init.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
273.73 ms | 1024 KiB | 19 Q