3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ class CustomArrayObject implements ArrayAccess, IteratorAggregate, Countable, Serializable { private $array; public function __construct(array $array = null) { $this->array = $array ?: array(); } public function offsetExists($offset) { return array_key_exists($offset, $this->array); } public function offsetGet($offset) { return $this->array[$offset]; } public function offsetSet($offset, $value) { if (null === $offset) { $this->array[] = $value; } else { $this->array[$offset] = $value; } } public function offsetUnset($offset) { unset($this->array[$offset]); } public function getIterator() { return new ArrayIterator($this->array); } public function count() { return count($this->array); } public function serialize() { return serialize($this->array); } public function unserialize($serialized) { $this->array = (array) unserialize((string) $serialized); } } $array = array('foo' => 'bar', 'nulled' => null); $native = new ArrayObject($array); $custom = new CustomArrayObject($array); error_reporting(-1); $a = array_key_exists('missing', $custom); var_dump(isset($custom['missing']) || array_key_exists('missing', $custom));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/Zvj6r
function name:  (null)
number of ops:  23
compiled vars:  !0 = $array, !1 = $native, !2 = $custom, !3 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   DECLARE_CLASS                                            'customarrayobject'
   71     1        ASSIGN                                                   !0, <array>
   72     2        NEW                                              $5      'ArrayObject'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   73     6        NEW                                              $8      'CustomArrayObject'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $8
   75    10        INIT_FCALL                                               'error_reporting'
         11        SEND_VAL                                                 -1
         12        DO_ICALL                                                 
   76    13        ARRAY_KEY_EXISTS                                 ~12     'missing', !2
         14        ASSIGN                                                   !3, ~12
   77    15        INIT_FCALL                                               'var_dump'
         16        ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !2, 'missing'
         17      > JMPNZ_EX                                         ~14     ~14, ->20
         18    >   ARRAY_KEY_EXISTS                                 ~15     'missing', !2
         19        BOOL                                             ~14     ~15
         20    >   SEND_VAL                                                 ~14
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Class CustomArrayObject:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  __construct
number of ops:  6
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV_INIT                                        !0      null
   23     1        JMP_SET                                          ~2      !0, ->3
          2        QM_ASSIGN                                        ~2      <array>
          3        ASSIGN_OBJ                                               'array'
          4        OP_DATA                                                  ~2
   24     5      > RETURN                                                   null

End of function __construct

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        FETCH_OBJ_R                                      ~1      'array'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3      > RETURN                                                   ~2
   29     4*     > RETURN                                                   null

End of function offsetexists

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  offsetGet
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        FETCH_OBJ_R                                      ~1      'array'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   34     4*     > RETURN                                                   null

End of function offsetget

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
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/Zvj6r
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->8
   39     4    >   FETCH_OBJ_W                                      $3      'array'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
   41     8    >   FETCH_OBJ_W                                      $5      'array'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
   43    11    > > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        FETCH_OBJ_UNSET                                  $1      'array'
          2        UNSET_DIM                                                $1, !0
   48     3      > RETURN                                                   null

End of function offsetunset

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  getIterator
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   NEW                                              $0      'ArrayIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      'array'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $0
   53     6*     > RETURN                                                   null

End of function getiterator

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  count
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   FETCH_OBJ_R                                      ~0      'array'
          1        COUNT                                            ~1      ~0
          2      > RETURN                                                   ~1
   58     3*     > RETURN                                                   null

End of function count

Function serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  serialize
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_FCALL                                               'serialize'
          1        FETCH_OBJ_R                                      ~0      'array'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   63     5*     > RETURN                                                   null

End of function serialize

Function unserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zvj6r
function name:  unserialize
number of ops:  9
compiled vars:  !0 = $serialized
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
   67     1        INIT_FCALL                                               'unserialize'
          2        CAST                                          6  ~2      !0
          3        SEND_VAL                                                 ~2
          4        DO_ICALL                                         $3      
          5        CAST                                          7  ~4      $3
          6        ASSIGN_OBJ                                               'array'
          7        OP_DATA                                                  ~4
   68     8      > RETURN                                                   null

End of function unserialize

End of class CustomArrayObject.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.52 ms | 1396 KiB | 21 Q