3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Acd; /** * Registry class * * Simple class to store or get elements from configuration registry */ class Registry { /** @var array Registry configuration array */ private $data = []; /** * Class constructor * @param array $data List of values to add to the registry */ public function __construct(array $data = []) { if(!empty($data)) { foreach ($data as $key => $value) { $this->set($key, $value); } } } public function offsetSet($key, $value) { if (!$key) { $this->data[] = $value; } else { $this->data[$key] = $value; } } /** * Key to retrieve * * @param mixed $key * @return string|null */ public function offsetGet($key) { if (isset($this->data[$key])) { return $this->data[$key]; } return null; } /** * Whether a key exists * * @param mixed $key * @return bool */ public function offsetExists($key) { return isset($this->data[$key]); } /** * Key to unset * * @param mixed $key */ public function offsetUnset($key) { unset($this->data[$key]); } /** * Adds element to registry array * * @param string $key - registry Key * @param mixed $value - registry Value * @throws Exception When there is a duplicate $key */ public function set($key, $value) { if (isset($this->data[$key])) { throw new \Exception('There is already an entry for key: ' . $key); } $this->data[$key] = $value; } /** * Retrieves elements from registry array * * @param string $key * @return mixed returns a registry value * @throws Exception when no $key found */ public function get($key) { if (!isset($this->data[$key])) { throw new \Exception('There is no entry for key: ' . $key); } return $this->data[$key]; } /** * Remove an entry from the Registry * * @param string $key * @return void */ public function remove($key) { unset($this->data[$key]); } /** * Return true if value is empty for given key * * @param string $key * @return bool */ public function isEmpty($key) { return empty($this->data[$key]); } /** * Reset Registry container */ public function reset() { $this->data = []; } /** * Return total number of data elements * @return int */ public function count() { return count($this->data); } /** * IteratorAggregate interface required method * * @return \ArrayIterator */ public function getIterator() { return new \ArrayIterator($this->data); } } class Main { private $registry = null; private $service = null; private $obj = null; public function __construct() { if (!($this->registry instanceof Registry)) { $this->registry = new Registry; } } public function getService($service) { return $this->registry->get($service); } public function setService($class, array $args = null) { return $this->registry->set($class, function() use ($class, $args) { $class = $this->isValidService($class); return new $class($args); }); } private function isValidService($classname) { $classname = __NAMESPACE__ . '\\' . ucwords($classname); if(class_exists($classname)) { return $classname; } else { throw new \Exception("Invalid class name given: " . $classname); } } /** * Magic method to retrieve the Object * @param string $obj * @return object Object instance */ public function __get($obj) { $obj = $this->registry->get($obj); return $obj(); } } // Initialize main class $app = new Acd\Main(); // Start Request Service $app->setService('request');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  (null)
number of ops:  7
compiled vars:  !0 = $app
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  214     0  E >   NEW                                              $1      'Acd%5CAcd%5CMain'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
  217     3        INIT_METHOD_CALL                                         !0, 'setService'
          4        SEND_VAL_EX                                              'request'
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Function %00acd%5C%7Bclosure%7D%2Fin%2Fsa2So%3A183%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  Acd\{closure}
number of ops:  13
compiled vars:  !0 = $class, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  183     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
          2        FETCH_THIS                                       $2      
          3        INIT_METHOD_CALL                                         $2, 'isValidService'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !0, $3
          7        FETCH_CLASS                                   0  $5      !0
          8        NEW                                              $6      $5
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11      > RETURN                                                   $6
         12*     > RETURN                                                   null

End of function %00acd%5C%7Bclosure%7D%2Fin%2Fsa2So%3A183%240

Class Acd\Registry:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 13
filename:       /in/sa2So
function name:  __construct
number of ops:  14
compiled vars:  !0 = $data, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_INIT                                        !0      <array>
   24     1        ISSET_ISEMPTY_CV                                 ~3      !0
          2        BOOL_NOT                                         ~4      ~3
          3      > JMPZ                                                     ~4, ->13
   25     4    > > FE_RESET_R                                       $5      !0, ->12
          5    > > FE_FETCH_R                                       ~6      $5, !1, ->12
          6    >   ASSIGN                                                   !2, ~6
   26     7        INIT_METHOD_CALL                                         'set'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
   25    11      > JMP                                                      ->5
         12    >   FE_FREE                                                  $5
   29    13    > > RETURN                                                   null

End of function __construct

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/sa2So
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        BOOL_NOT                                         ~2      !0
          3      > JMPZ                                                     ~2, ->8
   35     4    >   FETCH_OBJ_W                                      $3      'data'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
   38     8    >   FETCH_OBJ_W                                      $5      'data'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
   40    11    > > RETURN                                                   null

End of function offsetset

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  offsetGet
number of ops:  9
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   50     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   52     4    >   FETCH_OBJ_R                                      ~3      'data'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
   54     7    > > RETURN                                                   null
   55     8*     > RETURN                                                   null

End of function offsetget

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   65     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   66     4*     > RETURN                                                   null

End of function offsetexists

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

End of function offsetunset

Function set:
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 = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  set
number of ops:  14
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   88     2        FETCH_OBJ_IS                                     ~2      'data'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          4      > JMPZ                                                     ~3, ->10
   90     5    >   NEW                                              $4      'Exception'
          6        CONCAT                                           ~5      'There+is+already+an+entry+for+key%3A+', !0
          7        SEND_VAL_EX                                              ~5
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $4
   93    10    >   FETCH_OBJ_W                                      $7      'data'
         11        ASSIGN_DIM                                               $7, !0
         12        OP_DATA                                                  !1
   94    13      > RETURN                                                   null

End of function set

Function get:
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 = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  get
number of ops:  14
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   RECV                                             !0      
  105     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->10
  107     5    >   NEW                                              $4      'Exception'
          6        CONCAT                                           ~5      'There+is+no+entry+for+key%3A+', !0
          7        SEND_VAL_EX                                              ~5
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $4
  110    10    >   FETCH_OBJ_R                                      ~7      'data'
         11        FETCH_DIM_R                                      ~8      ~7, !0
         12      > RETURN                                                   ~8
  111    13*     > RETURN                                                   null

End of function get

Function remove:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  remove
number of ops:  4
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  119     0  E >   RECV                                             !0      
  121     1        FETCH_OBJ_UNSET                                  $1      'data'
          2        UNSET_DIM                                                $1, !0
  122     3      > RETURN                                                   null

End of function remove

Function isempty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  isEmpty
number of ops:  5
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  130     0  E >   RECV                                             !0      
  132     1        FETCH_OBJ_IS                                     ~1      'data'
          2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      ~1, !0
          3      > RETURN                                                   ~2
  133     4*     > RETURN                                                   null

End of function isempty

Function reset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  reset
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  139     0  E >   ASSIGN_OBJ                                               'data'
          1        OP_DATA                                                  <array>
  140     2      > RETURN                                                   null

End of function reset

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  count
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  148     0  E >   INIT_NS_FCALL_BY_NAME                                    'Acd%5Ccount'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'data'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
  149     6*     > RETURN                                                   null

End of function count

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

End of function getiterator

End of class Acd\Registry.

Class Acd\Main:
Function __construct:
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 = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/sa2So
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  170     0  E >   FETCH_OBJ_R                                      ~0      'registry'
          1        INSTANCEOF                                       ~1      ~0, 'Acd%5CRegistry'
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->8
  172     4    >   NEW                                              $4      'Acd%5CRegistry'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'registry'
          7        OP_DATA                                                  $4
  174     8    > > RETURN                                                   null

End of function __construct

Function getservice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  getService
number of ops:  7
compiled vars:  !0 = $service
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  176     0  E >   RECV                                             !0      
  178     1        FETCH_OBJ_R                                      ~1      'registry'
          2        INIT_METHOD_CALL                                         ~1, 'get'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
  179     6*     > RETURN                                                   null

End of function getservice

Function setservice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  setService
number of ops:  12
compiled vars:  !0 = $class, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  181     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
  183     2        FETCH_OBJ_R                                      ~2      'registry'
          3        INIT_METHOD_CALL                                         ~2, 'set'
          4        SEND_VAR_EX                                              !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00acd%5C%7Bclosure%7D%2Fin%2Fsa2So%3A183%240'
          6        BIND_LEXICAL                                             ~3, !0
          7        BIND_LEXICAL                                             ~3, !1
          8        SEND_VAL_EX                                              ~3
          9        DO_FCALL                                      0  $4      
         10      > RETURN                                                   $4
  184    11*     > RETURN                                                   null

End of function setservice

Function isvalidservice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/sa2So
function name:  isValidService
number of ops:  18
compiled vars:  !0 = $classname
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  186     0  E >   RECV                                             !0      
  188     1        INIT_NS_FCALL_BY_NAME                                    'Acd%5Cucwords'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        CONCAT                                           ~2      'Acd%5C', $1
          5        ASSIGN                                                   !0, ~2
  189     6        INIT_NS_FCALL_BY_NAME                                    'Acd%5Cclass_exists'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $4      
          9      > JMPZ                                                     $4, ->12
  191    10    > > RETURN                                                   !0
         11*       JMP                                                      ->17
  194    12    >   NEW                                              $5      'Exception'
         13        CONCAT                                           ~6      'Invalid+class+name+given%3A+', !0
         14        SEND_VAL_EX                                              ~6
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $5
  196    17*     > RETURN                                                   null

End of function isvalidservice

Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sa2So
function name:  __get
number of ops:  10
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  203     0  E >   RECV                                             !0      
  205     1        FETCH_OBJ_R                                      ~1      'registry'
          2        INIT_METHOD_CALL                                         ~1, 'get'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !0, $2
  206     6        INIT_DYNAMIC_CALL                                        !0
          7        DO_FCALL                                      0  $4      
          8      > RETURN                                                   $4
  207     9*     > RETURN                                                   null

End of function __get

End of class Acd\Main.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.62 ms | 1416 KiB | 19 Q