3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ConstructorException extends Exception {} class Foo extends ArrayObject { public function __construct( $arr = array(), $flags = 0, $iterator = 'FooIterator' ) { parent::__construct( $arr, $flags, $iterator ); } /** * @return ArrayIterator */ public function getIterator() { $class = $this->getIteratorClass(); return new $class($this); } } class FooIterator extends ArrayIterator { function __construct( $array = array(), $flags = 0 ) { unset( $array[0] , $array[1] ); parent::__construct( $array, $flags ); } } try { $f = new Foo( array( 1, 2, 3 ) ); $it = $f->getIterator(); $it->offsetSet(5, 10); $f[7] = 11; while ($it->valid()) { echo $it->key() . ' => ' . $it->current() . "\n"; $it->next(); } if ( get_class( $it ) !== 'FooIterator' ) { throw new Exception( 'Expected iterator to be FooIterator.' ); } die( "FAIL\n" ); } catch ( ConstructorException $e ) { die( "PASS\n" ); } catch ( \Exception $e ) { die( sprintf( "ERROR: %s\n", $e->getMessage() ) ); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 14
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 14
Branch analysis from position: 27
Branch analysis from position: 14
Found catch point at position: 36
Branch analysis from position: 36
2 jumps found. (Code = 107) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 107) Position 1 = 40, Position 2 = -2
Branch analysis from position: 40
1 jumps found. (Code = 79) Position 1 = -2
Found catch point at position: 39
Branch analysis from position: 39
filename:       /in/R8PHr
function name:  (null)
number of ops:  48
compiled vars:  !0 = $f, !1 = $it, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $3      'Foo'
          1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   30     4        INIT_METHOD_CALL                                         !0, 'getIterator'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !1, $6
   32     7        INIT_METHOD_CALL                                         !1, 'offsetSet'
          8        SEND_VAL_EX                                              5
          9        SEND_VAL_EX                                              10
         10        DO_FCALL                                      0          
   34    11        ASSIGN_DIM                                               !0, 7
         12        OP_DATA                                                  11
   36    13      > JMP                                                      ->24
   37    14    >   INIT_METHOD_CALL                                         !1, 'key'
         15        DO_FCALL                                      0  $10     
         16        CONCAT                                           ~11     $10, '+%3D%3E+'
         17        INIT_METHOD_CALL                                         !1, 'current'
         18        DO_FCALL                                      0  $12     
         19        CONCAT                                           ~13     ~11, $12
         20        CONCAT                                           ~14     ~13, '%0A'
         21        ECHO                                                     ~14
   39    22        INIT_METHOD_CALL                                         !1, 'next'
         23        DO_FCALL                                      0          
   36    24    >   INIT_METHOD_CALL                                         !1, 'valid'
         25        DO_FCALL                                      0  $16     
         26      > JMPNZ                                                    $16, ->14
   42    27    >   GET_CLASS                                        ~17     !1
         28        IS_NOT_IDENTICAL                                         ~17, 'FooIterator'
         29      > JMPZ                                                     ~18, ->34
   43    30    >   NEW                                              $19     'Exception'
         31        SEND_VAL_EX                                              'Expected+iterator+to+be+FooIterator.'
         32        DO_FCALL                                      0          
         33      > THROW                                         0          $19
   45    34    > > EXIT                                                     'FAIL%0A'
         35*       JMP                                                      ->47
   46    36  E > > CATCH                                                    'ConstructorException', ->39
   47    37    > > EXIT                                                     'PASS%0A'
         38*       JMP                                                      ->47
   48    39  E > > CATCH                                       last         'Exception'
   49    40    >   INIT_FCALL                                               'sprintf'
         41        SEND_VAL                                                 'ERROR%3A+%25s%0A'
         42        INIT_METHOD_CALL                                         !2, 'getMessage'
         43        DO_FCALL                                      0  $21     
         44        SEND_VAR                                                 $21
         45        DO_ICALL                                         $22     
         46      > EXIT                                                     $22
   50    47*     > RETURN                                                   1

Class ConstructorException: [no user functions]
Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8PHr
function name:  __construct
number of ops:  9
compiled vars:  !0 = $arr, !1 = $flags, !2 = $iterator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV_INIT                                        !0      <array>
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      'FooIterator'
    8     3        INIT_STATIC_METHOD_CALL                                  
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        DO_FCALL                                      0          
    9     8      > RETURN                                                   null

End of function __construct

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8PHr
function name:  getIterator
number of ops:  10
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_METHOD_CALL                                         'getIteratorClass'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   17     3        FETCH_CLASS                                   0  $3      !0
          4        NEW                                              $4      $3
          5        FETCH_THIS                                       $5      
          6        SEND_VAR_EX                                              $5
          7        DO_FCALL                                      0          
          8      > RETURN                                                   $4
   18     9*     > RETURN                                                   null

End of function getiterator

End of class Foo.

Class FooIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8PHr
function name:  __construct
number of ops:  9
compiled vars:  !0 = $array, !1 = $flags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_INIT                                        !0      <array>
          1        RECV_INIT                                        !1      0
   23     2        UNSET_DIM                                                !0, 0
          3        UNSET_DIM                                                !0, 1
   24     4        INIT_STATIC_METHOD_CALL                                  
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
   25     8      > RETURN                                                   null

End of function __construct

End of class FooIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.54 ms | 1019 KiB | 14 Q