3v4l.org

run code in 300+ PHP versions simultaneously
<?php Class ObjectPool { private $objectPool = array(); private $object; public function __construct($object) { $this->object = $object; } public function release() { $this->objectPool[] = $this->object; } public function get() { if (count($this->objectPool) > 0) { return array_pop($objectPool); } return new $this->object; } } Class Test { public $id = 1; } $pool = new ObjectPool('Test'); $testWorker = $pool->get(); $testWorker2 = $pool->get(); var_dump($testWorker); var_dump($testWorker2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UHpg3
function name:  (null)
number of ops:  17
compiled vars:  !0 = $pool, !1 = $testWorker, !2 = $testWorker2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   NEW                                              $3      'ObjectPool'
          1        SEND_VAL_EX                                              'Test'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   34     4        INIT_METHOD_CALL                                         !0, 'get'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !1, $6
   35     7        INIT_METHOD_CALL                                         !0, 'get'
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !2, $8
   37    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   38    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

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

End of function __construct

Function release:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UHpg3
function name:  release
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                      ~2      'object'
          1        FETCH_OBJ_W                                      $0      'objectPool'
          2        ASSIGN_DIM                                               $0
          3        OP_DATA                                                  ~2
   16     4      > RETURN                                                   null

End of function release

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UHpg3
function name:  get
number of ops:  14
compiled vars:  !0 = $objectPool
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~1      'objectPool'
          1        COUNT                                            ~2      ~1
          2        IS_SMALLER                                               0, ~2
          3      > JMPZ                                                     ~3, ->8
   21     4    >   INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $4      
          7      > RETURN                                                   $4
   24     8    >   FETCH_OBJ_R                                      ~5      'object'
          9        FETCH_CLASS                                   0  $6      ~5
         10        NEW                                              $7      $6
         11        DO_FCALL                                      0          
         12      > RETURN                                                   $7
   25    13*     > RETURN                                                   null

End of function get

End of class ObjectPool.

Class Test: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
198.02 ms | 1400 KiB | 17 Q