3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Ampersand\DevTest\BasicOop; interface NumberInterface { /** * Adds n to this number * * @param int $n The amount to add to this number * @return int The new integer value of this number */ public function add($n); /** * Subtracts n from this number * * @param int $n The amount to subtract from this number * @return int The new integer value of this number */ public function subtract($n); /** * Multiplies this number by n * * @param int $n The amount to multiply this number by * @return int The new integer value of this number */ public function multiply($n); /** * Divides this number by n * * @param int $n The amount to divide this number by * @return int The new integer value of this number */ public function divide($n); /** * Returns the integer value of this number * * @return int The current integer value of this number */ public function toInt(); } class NumberTest { public function testConstruct() { $n = new Number; $this->assertEquals(0, $n->toInt()); $n = new Number(0); $this->assertEquals(0, $n->toInt()); $n = new Number(3); $this->assertEquals(3, $n->toInt()); } public function testAdd() { $n = new Number; $n->add(5); $this->assertEquals(5, $n->toInt()); $n->add(-7); $this->assertEquals(-2, $n->toInt()); } public function testSubtract() { $n = new Number; $n->subtract(8); $this->assertEquals(-8, $n->toInt()); $n->subtract(-10); $this->assertEquals(2, $n->toInt()); } public function testMultiply() { $n = new Number(1); $n->multiply(10); $this->assertEquals(10, $n->toInt()); $n->multiply(6); $this->assertEquals(60, $n->toInt()); } public function testDivide() { $n = new Number(100); $n->divide(5); $this->assertEquals(20, $n->toInt()); $n->divide(5); $this->assertEquals(4, $n->toInt()); $hasThrownEx = false; try { $n->divide(0); } catch (\InvalidArgumentException $e) { $hasThrownEx = true; } $this->assertEquals(true, $hasThrownEx); } private function assertEquals($expected, $actual) { if ($expect !== $actual) { echo "\n"; var_dump($actual); echo ' does not match expected '; var_dump($expected); echo "\n"; } } } class Number implements NumberInterface { private $value; public function __construct($value = 0) { $this->value = $value; } public function add($value) { $this->value += $value; return $this->value; } public function subtract($value) { $this->value -= $value; return $this->value; } public function multiply($value) { $this->value *= $value; return $this->value; } public function divide($value) { if (0 === $value) { throw new \InvalidArgumentException; } $this->value /= $value; return $this->value; } public function toInt() { return $this->value; } } $test = new NumberTest; $test->testConstruct(); $test->testAdd(); $test->testSubtract(); $test->testMultiply(); $test->testDivide();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  (null)
number of ops:  15
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  125     0  E >   DECLARE_CLASS                                            'ampersand%5Cdevtest%5Cbasicoop%5Cnumber'
  168     1        NEW                                              $1      'Ampersand%5CDevTest%5CBasicOop%5CNumberTest'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
  169     4        INIT_METHOD_CALL                                         !0, 'testConstruct'
          5        DO_FCALL                                      0          
  170     6        INIT_METHOD_CALL                                         !0, 'testAdd'
          7        DO_FCALL                                      0          
  171     8        INIT_METHOD_CALL                                         !0, 'testSubtract'
          9        DO_FCALL                                      0          
  172    10        INIT_METHOD_CALL                                         !0, 'testMultiply'
         11        DO_FCALL                                      0          
  173    12        INIT_METHOD_CALL                                         !0, 'testDivide'
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

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

End of function add

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

End of function subtract

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

End of function multiply

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

End of function divide

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

End of function toint

End of class Ampersand\DevTest\BasicOop\NumberInterface.

Class Ampersand\DevTest\BasicOop\NumberTest:
Function testconstruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  testConstruct
number of ops:  30
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   NEW                                              $1      'Ampersand%5CDevTest%5CBasicOop%5CNumber'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   51     3        INIT_METHOD_CALL                                         'assertEquals'
          4        SEND_VAL_EX                                              0
          5        INIT_METHOD_CALL                                         !0, 'toInt'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR_NO_REF_EX                                       $4
          8        DO_FCALL                                      0          
   54     9        NEW                                              $6      'Ampersand%5CDevTest%5CBasicOop%5CNumber'
         10        SEND_VAL_EX                                              0
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !0, $6
   55    13        INIT_METHOD_CALL                                         'assertEquals'
         14        SEND_VAL_EX                                              0
         15        INIT_METHOD_CALL                                         !0, 'toInt'
         16        DO_FCALL                                      0  $9      
         17        SEND_VAR_NO_REF_EX                                       $9
         18        DO_FCALL                                      0          
   57    19        NEW                                              $11     'Ampersand%5CDevTest%5CBasicOop%5CNumber'
         20        SEND_VAL_EX                                              3
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !0, $11
   58    23        INIT_METHOD_CALL                                         'assertEquals'
         24        SEND_VAL_EX                                              3
         25        INIT_METHOD_CALL                                         !0, 'toInt'
         26        DO_FCALL                                      0  $14     
         27        SEND_VAR_NO_REF_EX                                       $14
         28        DO_FCALL                                      0          
   59    29      > RETURN                                                   null

End of function testconstruct

Function testadd:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  testAdd
number of ops:  22
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   NEW                                              $1      'Ampersand%5CDevTest%5CBasicOop%5CNumber'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   65     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAL_EX                                              5
          5        DO_FCALL                                      0          
   66     6        INIT_METHOD_CALL                                         'assertEquals'
          7        SEND_VAL_EX                                              5
          8        INIT_METHOD_CALL                                         !0, 'toInt'
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR_NO_REF_EX                                       $5
         11        DO_FCALL                                      0          
   68    12        INIT_METHOD_CALL                                         !0, 'add'
         13        SEND_VAL_EX                                              -7
         14        DO_FCALL                                      0          
   69    15        INIT_METHOD_CALL                                         'assertEquals'
         16        SEND_VAL_EX                                              -2
         17        INIT_METHOD_CALL                                         !0, 'toInt'
         18        DO_FCALL                                      0  $8      
         19        SEND_VAR_NO_REF_EX                                       $8
         20        DO_FCALL                                      0          
   70    21      > RETURN                                                   null

End of function testadd

Function testsubtract:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  testSubtract
number of ops:  22
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   NEW                                              $1      'Ampersand%5CDevTest%5CBasicOop%5CNumber'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   76     3        INIT_METHOD_CALL                                         !0, 'subtract'
          4        SEND_VAL_EX                                              8
          5        DO_FCALL                                      0          
   77     6        INIT_METHOD_CALL                                         'assertEquals'
          7        SEND_VAL_EX                                              -8
          8        INIT_METHOD_CALL                                         !0, 'toInt'
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR_NO_REF_EX                                       $5
         11        DO_FCALL                                      0          
   79    12        INIT_METHOD_CALL                                         !0, 'subtract'
         13        SEND_VAL_EX                                              -10
         14        DO_FCALL                                      0          
   80    15        INIT_METHOD_CALL                                         'assertEquals'
         16        SEND_VAL_EX                                              2
         17        INIT_METHOD_CALL                                         !0, 'toInt'
         18        DO_FCALL                                      0  $8      
         19        SEND_VAR_NO_REF_EX                                       $8
         20        DO_FCALL                                      0          
   81    21      > RETURN                                                   null

End of function testsubtract

Function testmultiply:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  testMultiply
number of ops:  23
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   NEW                                              $1      'Ampersand%5CDevTest%5CBasicOop%5CNumber'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   87     4        INIT_METHOD_CALL                                         !0, 'multiply'
          5        SEND_VAL_EX                                              10
          6        DO_FCALL                                      0          
   88     7        INIT_METHOD_CALL                                         'assertEquals'
          8        SEND_VAL_EX                                              10
          9        INIT_METHOD_CALL                                         !0, 'toInt'
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR_NO_REF_EX                                       $5
         12        DO_FCALL                                      0          
   90    13        INIT_METHOD_CALL                                         !0, 'multiply'
         14        SEND_VAL_EX                                              6
         15        DO_FCALL                                      0          
   91    16        INIT_METHOD_CALL                                         'assertEquals'
         17        SEND_VAL_EX                                              60
         18        INIT_METHOD_CALL                                         !0, 'toInt'
         19        DO_FCALL                                      0  $8      
         20        SEND_VAR_NO_REF_EX                                       $8
         21        DO_FCALL                                      0          
   92    22      > RETURN                                                   null

End of function testmultiply

Function testdivide:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 27
Branch analysis from position: 27
2 jumps found. (Code = 107) Position 1 = 28, Position 2 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  testDivide
number of ops:  34
compiled vars:  !0 = $n, !1 = $hasThrownEx, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   NEW                                              $3      'Ampersand%5CDevTest%5CBasicOop%5CNumber'
          1        SEND_VAL_EX                                              100
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   98     4        INIT_METHOD_CALL                                         !0, 'divide'
          5        SEND_VAL_EX                                              5
          6        DO_FCALL                                      0          
   99     7        INIT_METHOD_CALL                                         'assertEquals'
          8        SEND_VAL_EX                                              20
          9        INIT_METHOD_CALL                                         !0, 'toInt'
         10        DO_FCALL                                      0  $7      
         11        SEND_VAR_NO_REF_EX                                       $7
         12        DO_FCALL                                      0          
  101    13        INIT_METHOD_CALL                                         !0, 'divide'
         14        SEND_VAL_EX                                              5
         15        DO_FCALL                                      0          
  102    16        INIT_METHOD_CALL                                         'assertEquals'
         17        SEND_VAL_EX                                              4
         18        INIT_METHOD_CALL                                         !0, 'toInt'
         19        DO_FCALL                                      0  $10     
         20        SEND_VAR_NO_REF_EX                                       $10
         21        DO_FCALL                                      0          
  104    22        ASSIGN                                                   !1, <false>
  106    23        INIT_METHOD_CALL                                         !0, 'divide'
         24        SEND_VAL_EX                                              0
         25        DO_FCALL                                      0          
         26      > JMP                                                      ->29
  107    27  E > > CATCH                                       last         'InvalidArgumentException'
  108    28    >   ASSIGN                                                   !1, <true>
  110    29    >   INIT_METHOD_CALL                                         'assertEquals'
         30        SEND_VAL_EX                                              <true>
         31        SEND_VAR_EX                                              !1
         32        DO_FCALL                                      0          
  111    33      > RETURN                                                   null

End of function testdivide

Function assertequals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ccKr7
function name:  assertEquals
number of ops:  14
compiled vars:  !0 = $expected, !1 = $actual, !2 = $expect
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  115     2        IS_NOT_IDENTICAL                                         !2, !1
          3      > JMPZ                                                     ~3, ->13
  116     4    >   ECHO                                                     '%0A'
  117     5        INIT_NS_FCALL_BY_NAME                                    'Ampersand%5CDevTest%5CBasicOop%5Cvar_dump'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
  118     8        ECHO                                                     '+does+not+match+expected+'
  119     9        INIT_NS_FCALL_BY_NAME                                    'Ampersand%5CDevTest%5CBasicOop%5Cvar_dump'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
  120    12        ECHO                                                     '%0A'
  122    13    > > RETURN                                                   null

End of function assertequals

End of class Ampersand\DevTest\BasicOop\NumberTest.

Class Ampersand\DevTest\BasicOop\Number:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  __construct
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  129     0  E >   RECV_INIT                                        !0      0
  131     1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
  132     3      > RETURN                                                   null

End of function __construct

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  add
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  134     0  E >   RECV                                             !0      
  136     1        ASSIGN_OBJ_OP                                 1          'value'
          2        OP_DATA                                                  !0
  137     3        FETCH_OBJ_R                                      ~2      'value'
          4      > RETURN                                                   ~2
  138     5*     > RETURN                                                   null

End of function add

Function subtract:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  subtract
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  140     0  E >   RECV                                             !0      
  142     1        ASSIGN_OBJ_OP                                 2          'value'
          2        OP_DATA                                                  !0
  143     3        FETCH_OBJ_R                                      ~2      'value'
          4      > RETURN                                                   ~2
  144     5*     > RETURN                                                   null

End of function subtract

Function multiply:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  multiply
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  146     0  E >   RECV                                             !0      
  148     1        ASSIGN_OBJ_OP                                 3          'value'
          2        OP_DATA                                                  !0
  149     3        FETCH_OBJ_R                                      ~2      'value'
          4      > RETURN                                                   ~2
  150     5*     > RETURN                                                   null

End of function multiply

Function divide:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccKr7
function name:  divide
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  152     0  E >   RECV                                             !0      
  154     1        IS_IDENTICAL                                             !0, 0
          2      > JMPZ                                                     ~1, ->6
  155     3    >   NEW                                              $2      'InvalidArgumentException'
          4        DO_FCALL                                      0          
          5      > THROW                                         0          $2
  158     6    >   ASSIGN_OBJ_OP                                 4          'value'
          7        OP_DATA                                                  !0
  159     8        FETCH_OBJ_R                                      ~5      'value'
          9      > RETURN                                                   ~5
  160    10*     > RETURN                                                   null

End of function divide

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

End of function toint

End of class Ampersand\DevTest\BasicOop\Number.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.08 ms | 1420 KiB | 15 Q