3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ContractVersion { private $end_date; public function __construct(\DateTimeImmutable $end_date) { $this->end_date = $end_date; } public function getEndDate(): \DateTimeImmutable { return $this->end_date; } } class VersionedContract { private $versions = []; public function __construct(\DateTimeImmutable $end_date) { $this->versions[] = new ContractVersion($end_date); } public function getEndDate(): \DateTimeImmutable { return $this->getCurrentVersion()->getEndDate(); } private function getCurrentVersion(): ContractVersion { return end($this->versions); } public function renew(\DateInterval $interval) { $this->versions[] = new ContractVersion($this->getEndDate()->add($interval)); } } $contract = new VersionedContract(new \DateTime('2017-10-10 10:10:00')); var_dump($contract->getEndDate()); // string(26) "2017-10-10 10:10:00.000000" $endDate = $contract->getEndDate(); var_dump($endDate); // same string(26) "2017-10-10 10:10:00.000000" $endDate->add(new \DateInterval('P1Y')); var_dump($endDate); // "2017-10-10 10:10:00.000000" var_dump($contract->getEndDate());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jUkbg
function name:  (null)
number of ops:  33
compiled vars:  !0 = $contract, !1 = $endDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $2      'VersionedContract'
          1        NEW                                              $3      'DateTime'
          2        SEND_VAL_EX                                              '2017-10-10+10%3A10%3A00'
          3        DO_FCALL                                      0          
          4        SEND_VAR_NO_REF_EX                                       $3
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   45     7        INIT_FCALL                                               'var_dump'
          8        INIT_METHOD_CALL                                         !0, 'getEndDate'
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                                 
   46    12        INIT_METHOD_CALL                                         !0, 'getEndDate'
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !1, $9
   48    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
   50    18        INIT_METHOD_CALL                                         !1, 'add'
         19        NEW                                              $12     'DateInterval'
         20        SEND_VAL_EX                                              'P1Y'
         21        DO_FCALL                                      0          
         22        SEND_VAR_NO_REF_EX                                       $12
         23        DO_FCALL                                      0          
   52    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                                 
   54    27        INIT_FCALL                                               'var_dump'
         28        INIT_METHOD_CALL                                         !0, 'getEndDate'
         29        DO_FCALL                                      0  $16     
         30        SEND_VAR                                                 $16
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

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

End of function __construct

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

End of function getenddate

End of class ContractVersion.

Class VersionedContract:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jUkbg
function name:  __construct
number of ops:  8
compiled vars:  !0 = $end_date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        NEW                                              $3      'ContractVersion'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        FETCH_OBJ_W                                      $1      'versions'
          5        ASSIGN_DIM                                               $1
          6        OP_DATA                                                  $3
   25     7      > RETURN                                                   null

End of function __construct

Function getenddate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jUkbg
function name:  getEndDate
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_METHOD_CALL                                         'getCurrentVersion'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         $0, 'getEndDate'
          3        DO_FCALL                                      0  $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   30     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function getenddate

Function getcurrentversion:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jUkbg
function name:  getCurrentVersion
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'end'
          1        FETCH_OBJ_W                                      $0      'versions'
          2        SEND_REF                                                 $0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   35     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function getcurrentversion

Function renew:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jUkbg
function name:  renew
number of ops:  13
compiled vars:  !0 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1        NEW                                              $3      'ContractVersion'
          2        INIT_METHOD_CALL                                         'getEndDate'
          3        DO_FCALL                                      0  $4      
          4        INIT_METHOD_CALL                                         $4, 'add'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $5      
          7        SEND_VAR_NO_REF_EX                                       $5
          8        DO_FCALL                                      0          
          9        FETCH_OBJ_W                                      $1      'versions'
         10        ASSIGN_DIM                                               $1
         11        OP_DATA                                                  $3
   40    12      > RETURN                                                   null

End of function renew

End of class VersionedContract.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.86 ms | 1404 KiB | 17 Q