3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Currency { public $currencyCode; public function __construct($currencyCode) { $this->currencyCode = $currencyCode; } public function equals(Currency $currency) { return $this->currencyCode === $currency->currencyCode; } } class Money { public $amount; public $currency; public function __construct($amount, Currency $currency = null) { $this->currency = $currency ?: new Currency('USD'); } } var_dump(new Money(55) == true); var_dump(new Money(55) === true); var_dump(null == false); var_dump(null === false); // $currency is passed in, $currency == true $revenue = new Money(55, new Currency('GBP')); var_dump($revenue->currency->equals(new Currency('GBP'))); // $currency is null, $currency == false $assets = new Money(55); var_dump($assets->currency->equals(new Currency('USD')));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sNM8R
function name:  (null)
number of ops:  53
compiled vars:  !0 = $revenue, !1 = $assets
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'var_dump'
          1        NEW                                              $2      'Money'
          2        SEND_VAL_EX                                              55
          3        DO_FCALL                                      0          
          4        BOOL                                             ~4      $2
          5        SEND_VAL                                                 ~4
          6        DO_ICALL                                                 
   30     7        INIT_FCALL                                               'var_dump'
          8        NEW                                              $6      'Money'
          9        SEND_VAL_EX                                              55
         10        DO_FCALL                                      0          
         11        TYPE_CHECK                                    8  ~8      $6
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                                 
   32    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                                 
   33    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAL                                                 <false>
         19        DO_ICALL                                                 
   36    20        NEW                                              $12     'Money'
         21        SEND_VAL_EX                                              55
         22        NEW                                              $13     'Currency'
         23        SEND_VAL_EX                                              'GBP'
         24        DO_FCALL                                      0          
         25        SEND_VAR_NO_REF_EX                                       $13
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !0, $12
   38    28        INIT_FCALL                                               'var_dump'
         29        FETCH_OBJ_R                                      ~17     !0, 'currency'
         30        INIT_METHOD_CALL                                         ~17, 'equals'
         31        NEW                                              $18     'Currency'
         32        SEND_VAL_EX                                              'GBP'
         33        DO_FCALL                                      0          
         34        SEND_VAR_NO_REF_EX                                       $18
         35        DO_FCALL                                      0  $20     
         36        SEND_VAR                                                 $20
         37        DO_ICALL                                                 
   41    38        NEW                                              $22     'Money'
         39        SEND_VAL_EX                                              55
         40        DO_FCALL                                      0          
         41        ASSIGN                                                   !1, $22
   43    42        INIT_FCALL                                               'var_dump'
         43        FETCH_OBJ_R                                      ~25     !1, 'currency'
         44        INIT_METHOD_CALL                                         ~25, 'equals'
         45        NEW                                              $26     'Currency'
         46        SEND_VAL_EX                                              'USD'
         47        DO_FCALL                                      0          
         48        SEND_VAR_NO_REF_EX                                       $26
         49        DO_FCALL                                      0  $28     
         50        SEND_VAR                                                 $28
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

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

End of function __construct

Function equals:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sNM8R
function name:  equals
number of ops:  6
compiled vars:  !0 = $currency
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        FETCH_OBJ_R                                      ~1      'currencyCode'
          2        FETCH_OBJ_R                                      ~2      !0, 'currencyCode'
          3        IS_IDENTICAL                                     ~3      ~1, ~2
          4      > RETURN                                                   ~3
   15     5*     > RETURN                                                   null

End of function equals

End of class Currency.

Class Money:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sNM8R
function name:  __construct
number of ops:  10
compiled vars:  !0 = $amount, !1 = $currency
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   25     2        JMP_SET                                          ~3      !1, ->7
          3        NEW                                              $4      'Currency'
          4        SEND_VAL_EX                                              'USD'
          5        DO_FCALL                                      0          
          6        QM_ASSIGN                                        ~3      $4
          7        ASSIGN_OBJ                                               'currency'
          8        OP_DATA                                                  ~3
   26     9      > RETURN                                                   null

End of function __construct

End of class Money.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.87 ms | 1400 KiB | 15 Q