3v4l.org

run code in 300+ PHP versions simultaneously
<?php class container { protected $storage=array(); public function add(test1 $obj) { if(!isset($this->storage[spl_object_hash($obj)])) { $this->storage[spl_object_hash($obj)]=$obj; } } } class test1 { public function __construct($s) { } } $o=new container(); $o->add(new test1("lalala")); // will be added $o->add(new test1("lololo")); // not added - NOT as expected var_dump(spl_object_hash(new test1('1'))); var_dump(spl_object_hash(new test1('2'))); $t=new test1("lalala"); $o=new container(); $o->add($t); // will be added $o->add($t); // not added - as expected var_dump($o);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K5cak
function name:  (null)
number of ops:  50
compiled vars:  !0 = $o, !1 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $2      'container'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   16     3        INIT_METHOD_CALL                                         !0, 'add'
          4        NEW                                              $5      'test1'
          5        SEND_VAL_EX                                              'lalala'
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $5
          8        DO_FCALL                                      0          
   17     9        INIT_METHOD_CALL                                         !0, 'add'
         10        NEW                                              $8      'test1'
         11        SEND_VAL_EX                                              'lololo'
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $8
         14        DO_FCALL                                      0          
   19    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'spl_object_hash'
         17        NEW                                              $11     'test1'
         18        SEND_VAL_EX                                              '1'
         19        DO_FCALL                                      0          
         20        SEND_VAR                                                 $11
         21        DO_ICALL                                         $13     
         22        SEND_VAR                                                 $13
         23        DO_ICALL                                                 
   20    24        INIT_FCALL                                               'var_dump'
         25        INIT_FCALL                                               'spl_object_hash'
         26        NEW                                              $15     'test1'
         27        SEND_VAL_EX                                              '2'
         28        DO_FCALL                                      0          
         29        SEND_VAR                                                 $15
         30        DO_ICALL                                         $17     
         31        SEND_VAR                                                 $17
         32        DO_ICALL                                                 
   22    33        NEW                                              $19     'test1'
         34        SEND_VAL_EX                                              'lalala'
         35        DO_FCALL                                      0          
         36        ASSIGN                                                   !1, $19
   23    37        NEW                                              $22     'container'
         38        DO_FCALL                                      0          
         39        ASSIGN                                                   !0, $22
   24    40        INIT_METHOD_CALL                                         !0, 'add'
         41        SEND_VAR_EX                                              !1
         42        DO_FCALL                                      0          
   25    43        INIT_METHOD_CALL                                         !0, 'add'
         44        SEND_VAR_EX                                              !1
         45        DO_FCALL                                      0          
   27    46        INIT_FCALL                                               'var_dump'
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                                 
         49      > RETURN                                                   1

Class container:
Function add:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/K5cak
function name:  add
number of ops:  15
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'spl_object_hash'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        FETCH_OBJ_IS                                     ~1      'storage'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~1, $2
          6        BOOL_NOT                                         ~4      ~3
          7      > JMPZ                                                     ~4, ->14
    6     8    >   INIT_FCALL                                               'spl_object_hash'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $6      
         11        FETCH_OBJ_W                                      $5      'storage'
         12        ASSIGN_DIM                                               $5, $6
         13        OP_DATA                                                  !0
    8    14    > > RETURN                                                   null

End of function add

End of class container.

Class test1:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K5cak
function name:  __construct
number of ops:  2
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function __construct

End of class test1.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.04 ms | 1392 KiB | 17 Q