3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ClockInterface { public function now(): DateTimeImmutable; } class BadMockClock implements ClockInterface { public function __construct(private readonly DateTimeImmutable $now = new DateTimeImmutable()) { } public function now(): DateTimeImmutable { return $this->now; } } class GoodMockClock implements ClockInterface { public function __construct(private readonly DateTimeImmutable $now = new DateTimeImmutable()) { } public function now(): DateTimeImmutable { return clone $this->now; } } class Clock implements ClockInterface { public function now(): DateTimeImmutable { return new DateTimeImmutable(); } } $clocks = [ new BadMockClock(), new GoodMockClock(), new Clock(), ]; shuffle($clocks); foreach ($clocks as $i => $clock) { $t1 = $clock->now(); $t2 = $clock->now(); if ($t1 === $t2) { echo "Clock mock leaks at index $i\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 32
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 32
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/02IVc
function name:  (null)
number of ops:  34
compiled vars:  !0 = $clocks, !1 = $clock, !2 = $i, !3 = $t1, !4 = $t2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'badmockclock'
   21     1        DECLARE_CLASS                                            'goodmockclock'
   33     2        DECLARE_CLASS                                            'clock'
   42     3        NEW                                              $5      'BadMockClock'
          4        DO_FCALL                                      0          
          5        INIT_ARRAY                                       ~7      $5
   43     6        NEW                                              $8      'GoodMockClock'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~7      $8
   44     9        NEW                                              $10     'Clock'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~7      $10
   41    12        ASSIGN                                                   !0, ~7
   47    13        INIT_FCALL                                               'shuffle'
         14        SEND_REF                                                 !0
         15        DO_ICALL                                                 
   49    16      > FE_RESET_R                                       $14     !0, ->32
         17    > > FE_FETCH_R                                       ~15     $14, !1, ->32
         18    >   ASSIGN                                                   !2, ~15
   50    19        INIT_METHOD_CALL                                         !1, 'now'
         20        DO_FCALL                                      0  $17     
         21        ASSIGN                                                   !3, $17
   51    22        INIT_METHOD_CALL                                         !1, 'now'
         23        DO_FCALL                                      0  $19     
         24        ASSIGN                                                   !4, $19
   53    25        IS_IDENTICAL                                             !3, !4
         26      > JMPZ                                                     ~21, ->31
   54    27    >   ROPE_INIT                                     3  ~23     'Clock+mock+leaks+at+index+'
         28        ROPE_ADD                                      1  ~23     ~23, !2
         29        ROPE_END                                      2  ~22     ~23, '%0A'
         30        ECHO                                                     ~22
   49    31    > > JMP                                                      ->17
         32    >   FE_FREE                                                  $14
   56    33      > RETURN                                                   1

Class ClockInterface:
Function now:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/02IVc
function name:  now
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function now

End of class ClockInterface.

Class BadMockClock:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/02IVc
function name:  __construct
number of ops:  4
compiled vars:  !0 = $now
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV_INIT                                        !0      <const ast>
          1        ASSIGN_OBJ                                               'now'
          2        OP_DATA                                                  !0
   12     3      > RETURN                                                   null

End of function __construct

Function now:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/02IVc
function name:  now
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                      ~0      'now'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   17     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function now

End of class BadMockClock.

Class GoodMockClock:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/02IVc
function name:  __construct
number of ops:  4
compiled vars:  !0 = $now
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV_INIT                                        !0      <const ast>
          1        ASSIGN_OBJ                                               'now'
          2        OP_DATA                                                  !0
   25     3      > RETURN                                                   null

End of function __construct

Function now:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/02IVc
function name:  now
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'now'
          1        CLONE                                            ~1      ~0
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   30     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function now

End of class GoodMockClock.

Class Clock:
Function now:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/02IVc
function name:  now
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   NEW                                              $0      'DateTimeImmutable'
          1        DO_FCALL                                      0          
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   38     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function now

End of class Clock.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.71 ms | 1007 KiB | 14 Q