3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Server { private $hostname; private $cpu; private $ram; public function __construct($hostname, $cpu, $ram) { $this->hostname = $hostname; $this->cpu = $cpu; $this->ram = $ram; } public function getHostname() { return $this->hostname; } public function setHostname($hostname) { return $this->hostname = ($hostname == null ? $this->_exception("Hostname must not be null.") : $hostname); } public function getCpu() { return $this->cpu; } public function setCpu($cpu) { return $this->cpu = ($cpu == null ? $this->_exception("CPU must not be null.") : $cpu); } public function getRam() { return $this->ram; } public function setRam($ram) { return $this->ram = ($ram == null ? $this->_exception("RAM must not be null.") : $ram); } public function getRamInGb() { return $this->ram / 1024; } public function addRam($ram) { return $this->ram = ($ram === null ? $this->_exception("RAM must not be null.") : $this->ram + $ram); } public function subRam($ram) { return $this->ram = ($this->ram - $ram < 0 ? $this->_exception("RAM must not result in a below-zero value.") : $this->ram - $ram); } protected function _exception($text = null) { throw new InvalidArgumentException($text); } } $server = new Server("test.com", "Intel Xeon E5-2680 v2 2.8Ghz", 1024); echo $server->getHostname(); // "test.com" echo $server->setHostname("test.com"); // "test.com" echo $server->getCpu(); // "Intel Xeon E5-2680 v2 2.8Ghz" echo $server->setCpu("Intel Xeon E5-2680 v3 2.8Ghz"); // "Intel Xeon E5-2680 v3 2.8Ghz" echo $server->getRam(); // 1024 echo $server->getRamInGb(); // 1 echo $server->addRam(1024); // 2048 echo $server->getRamInGb(); // 2 echo $server->subRam(1024); // 1024 echo $server->getRamInGb(); // 1 echo $server->subRam(1024); // 0 echo $server->getRamInGb(); // 0 echo $server->subRam(1024); // InvalidArgumentException echo $server->getRamInGb(); // 0 echo $server->setRam(1024); // 1024 echo $server->getRamInGb(); // 1 echo $server->setRam(-1024); // InvalidArgumentException echo $server->getRamInGb(); // 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  (null)
number of ops:  69
compiled vars:  !0 = $server
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   NEW                                              $1      'Server'
          1        SEND_VAL_EX                                              'test.com'
          2        SEND_VAL_EX                                              'Intel+Xeon+E5-2680+v2+2.8Ghz'
          3        SEND_VAL_EX                                              1024
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   67     6        INIT_METHOD_CALL                                         !0, 'getHostname'
          7        DO_FCALL                                      0  $4      
          8        ECHO                                                     $4
   68     9        INIT_METHOD_CALL                                         !0, 'setHostname'
         10        SEND_VAL_EX                                              'test.com'
         11        DO_FCALL                                      0  $5      
         12        ECHO                                                     $5
   69    13        INIT_METHOD_CALL                                         !0, 'getCpu'
         14        DO_FCALL                                      0  $6      
         15        ECHO                                                     $6
   70    16        INIT_METHOD_CALL                                         !0, 'setCpu'
         17        SEND_VAL_EX                                              'Intel+Xeon+E5-2680+v3+2.8Ghz'
         18        DO_FCALL                                      0  $7      
         19        ECHO                                                     $7
   71    20        INIT_METHOD_CALL                                         !0, 'getRam'
         21        DO_FCALL                                      0  $8      
         22        ECHO                                                     $8
   72    23        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         24        DO_FCALL                                      0  $9      
         25        ECHO                                                     $9
   73    26        INIT_METHOD_CALL                                         !0, 'addRam'
         27        SEND_VAL_EX                                              1024
         28        DO_FCALL                                      0  $10     
         29        ECHO                                                     $10
   74    30        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         31        DO_FCALL                                      0  $11     
         32        ECHO                                                     $11
   75    33        INIT_METHOD_CALL                                         !0, 'subRam'
         34        SEND_VAL_EX                                              1024
         35        DO_FCALL                                      0  $12     
         36        ECHO                                                     $12
   76    37        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         38        DO_FCALL                                      0  $13     
         39        ECHO                                                     $13
   77    40        INIT_METHOD_CALL                                         !0, 'subRam'
         41        SEND_VAL_EX                                              1024
         42        DO_FCALL                                      0  $14     
         43        ECHO                                                     $14
   78    44        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         45        DO_FCALL                                      0  $15     
         46        ECHO                                                     $15
   79    47        INIT_METHOD_CALL                                         !0, 'subRam'
         48        SEND_VAL_EX                                              1024
         49        DO_FCALL                                      0  $16     
         50        ECHO                                                     $16
   80    51        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         52        DO_FCALL                                      0  $17     
         53        ECHO                                                     $17
   81    54        INIT_METHOD_CALL                                         !0, 'setRam'
         55        SEND_VAL_EX                                              1024
         56        DO_FCALL                                      0  $18     
         57        ECHO                                                     $18
   82    58        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         59        DO_FCALL                                      0  $19     
         60        ECHO                                                     $19
   83    61        INIT_METHOD_CALL                                         !0, 'setRam'
         62        SEND_VAL_EX                                              -1024
         63        DO_FCALL                                      0  $20     
         64        ECHO                                                     $20
   84    65        INIT_METHOD_CALL                                         !0, 'getRamInGb'
         66        DO_FCALL                                      0  $21     
         67        ECHO                                                     $21
         68      > RETURN                                                   1

Class Server:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  __construct
number of ops:  10
compiled vars:  !0 = $hostname, !1 = $cpu, !2 = $ram
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        ASSIGN_OBJ                                               'hostname'
          4        OP_DATA                                                  !0
   11     5        ASSIGN_OBJ                                               'cpu'
          6        OP_DATA                                                  !1
   12     7        ASSIGN_OBJ                                               'ram'
          8        OP_DATA                                                  !2
   13     9      > RETURN                                                   null

End of function __construct

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

End of function gethostname

Function sethostname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  setHostname
number of ops:  13
compiled vars:  !0 = $hostname
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        IS_EQUAL                                                 !0, null
          2      > JMPZ                                                     ~2, ->8
          3    >   INIT_METHOD_CALL                                         '_exception'
          4        SEND_VAL_EX                                              'Hostname+must+not+be+null.'
          5        DO_FCALL                                      0  $3      
          6        QM_ASSIGN                                        ~4      $3
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~4      !0
          9    >   ASSIGN_OBJ                                       ~1      'hostname'
         10        OP_DATA                                                  ~4
         11      > RETURN                                                   ~1
   23    12*     > RETURN                                                   null

End of function sethostname

Function getcpu:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  getCpu
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'cpu'
          1      > RETURN                                                   ~0
   28     2*     > RETURN                                                   null

End of function getcpu

Function setcpu:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  setCpu
number of ops:  13
compiled vars:  !0 = $cpu
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   32     1        IS_EQUAL                                                 !0, null
          2      > JMPZ                                                     ~2, ->8
          3    >   INIT_METHOD_CALL                                         '_exception'
          4        SEND_VAL_EX                                              'CPU+must+not+be+null.'
          5        DO_FCALL                                      0  $3      
          6        QM_ASSIGN                                        ~4      $3
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~4      !0
          9    >   ASSIGN_OBJ                                       ~1      'cpu'
         10        OP_DATA                                                  ~4
         11      > RETURN                                                   ~1
   33    12*     > RETURN                                                   null

End of function setcpu

Function getram:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  getRam
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~0      'ram'
          1      > RETURN                                                   ~0
   38     2*     > RETURN                                                   null

End of function getram

Function setram:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  setRam
number of ops:  13
compiled vars:  !0 = $ram
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        IS_EQUAL                                                 !0, null
          2      > JMPZ                                                     ~2, ->8
          3    >   INIT_METHOD_CALL                                         '_exception'
          4        SEND_VAL_EX                                              'RAM+must+not+be+null.'
          5        DO_FCALL                                      0  $3      
          6        QM_ASSIGN                                        ~4      $3
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~4      !0
          9    >   ASSIGN_OBJ                                       ~1      'ram'
         10        OP_DATA                                                  ~4
         11      > RETURN                                                   ~1
   43    12*     > RETURN                                                   null

End of function setram

Function getramingb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  getRamInGb
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'ram'
          1        DIV                                              ~1      ~0, 1024
          2      > RETURN                                                   ~1
   48     3*     > RETURN                                                   null

End of function getramingb

Function addram:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  addRam
number of ops:  15
compiled vars:  !0 = $ram
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     1        TYPE_CHECK                                    2          !0
          2      > JMPZ                                                     ~2, ->8
          3    >   INIT_METHOD_CALL                                         '_exception'
          4        SEND_VAL_EX                                              'RAM+must+not+be+null.'
          5        DO_FCALL                                      0  $3      
          6        QM_ASSIGN                                        ~4      $3
          7      > JMP                                                      ->11
          8    >   FETCH_OBJ_R                                      ~5      'ram'
          9        ADD                                              ~6      ~5, !0
         10        QM_ASSIGN                                        ~4      ~6
         11    >   ASSIGN_OBJ                                       ~1      'ram'
         12        OP_DATA                                                  ~4
         13      > RETURN                                                   ~1
   53    14*     > RETURN                                                   null

End of function addram

Function subram:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa9XT
function name:  subRam
number of ops:  17
compiled vars:  !0 = $ram
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   57     1        FETCH_OBJ_R                                      ~2      'ram'
          2        SUB                                              ~3      ~2, !0
          3        IS_SMALLER                                               ~3, 0
          4      > JMPZ                                                     ~4, ->10
          5    >   INIT_METHOD_CALL                                         '_exception'
          6        SEND_VAL_EX                                              'RAM+must+not+result+in+a+below-zero+value.'
          7        DO_FCALL                                      0  $5      
          8        QM_ASSIGN                                        ~6      $5
          9      > JMP                                                      ->13
         10    >   FETCH_OBJ_R                                      ~7      'ram'
         11        SUB                                              ~8      ~7, !0
         12        QM_ASSIGN                                        ~6      ~8
         13    >   ASSIGN_OBJ                                       ~1      'ram'
         14        OP_DATA                                                  ~6
         15      > RETURN                                                   ~1
   58    16*     > RETURN                                                   null

End of function subram

Function _exception:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/sa9XT
function name:  _exception
number of ops:  6
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV_INIT                                        !0      null
   62     1        NEW                                              $1      'InvalidArgumentException'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > THROW                                         0          $1
   63     5*     > RETURN                                                   null

End of function _exception

End of class Server.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.54 ms | 1411 KiB | 13 Q