3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace { class Http { public static function get(string $url, array $params): Response { return new Response(json_encode(['url' => $url, 'params' => $params])); } } class Response { private $data = null; public function __construct($response) { $this->data = $response; } public function json() { return json_decode($this->data, true); } } } namespace Search { interface Specification { public function __invoke(array $params): array; } class Name implements Specification { private $name = null; public function __construct(string $name) { $this->name = $name; } public function __invoke(array $params): array { return [ 'name' => $this->name, ]; } } class Language implements Specification { const DEFAULT = 'en'; private $language = null; public function __construct(string $language) { $this->language = $language; } public function __invoke(array $params): array { return [ 'language' => $this->language ?? 'en', ]; } } class Fuzzy implements Specification { const DEFAULT = true; private $fuzzy = null; public function __construct(bool $fuzzy) { $this->fuzzy = $fuzzy; } public function __invoke(array $params): array { return [ 'fuzzy' => $this->fuzzy, ]; } } class Limit implements Specification { const DEFAULT = 10; private $max = null; public function __construct(int $limit) { $this->limit = $limit; } public function __invoke(array $params): array { return [ 'maxRows' => $this->limit ?: self::DEFAULT, ]; } } } namespace Api { interface Searchable { public function search(\Search\Specification... $criteria); } class Search implements Searchable { private $url = '/search'; private $defaults = [ 'maxRows' => \Search\Limit::DEFAULT, ]; public function search(\Search\Specification ...$criteria) { return \Http::get($this->url, array_reduce( $criteria, fn($params, $criteria) => $criteria($params) + $params, $this->defaults ))->json(); } } } namespace Controller { class Api { private $api; public function __construct(\Api\Searchable $someApi) { $this->api = $someApi; } public function search(string $name, int $limit = \Search\Limit::DEFAULT) { return $this->api->search( new \Search\Name($name), new \Search\Limit($limit) ); } public function lookup( string $name, string $language = \Search\Language::DEFAULT, bool $fuzzy = \Search\Fuzzy::DEFAULT, int $limit = \Search\Limit::DEFAULT ) { return $this->api->search( new \Search\Name($name), new \Search\Language($language), new \Search\Fuzzy($fuzzy), new \Search\Limit($limit) ); } } } namespace { $foo = new \Controller\Api(new \Api\Search()); var_export([ $foo->search('foo'), $foo->search('bar', 25), $foo->search('baz', 1), $foo->lookup('foo'), $foo->lookup('bar', 'de', false, 5), $foo->lookup('baz', 'za', true, 20), ]); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  (null)
number of ops:  47
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   DECLARE_CLASS                                            'search%5Cname'
   53     1        DECLARE_CLASS                                            'search%5Clanguage'
   72     2        DECLARE_CLASS                                            'search%5Cfuzzy'
   91     3        DECLARE_CLASS                                            'search%5Climit'
  118     4        DECLARE_CLASS                                            'api%5Csearch'
  174     5        NEW                                              $1      'Controller%5CApi'
          6        NEW                                              $2      'Api%5CSearch'
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $2
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $1
  176    11        INIT_FCALL                                               'var_export'
  177    12        INIT_METHOD_CALL                                         !0, 'search'
         13        SEND_VAL_EX                                              'foo'
         14        DO_FCALL                                      0  $6      
         15        INIT_ARRAY                                       ~7      $6
  178    16        INIT_METHOD_CALL                                         !0, 'search'
         17        SEND_VAL_EX                                              'bar'
         18        SEND_VAL_EX                                              25
         19        DO_FCALL                                      0  $8      
         20        ADD_ARRAY_ELEMENT                                ~7      $8
  179    21        INIT_METHOD_CALL                                         !0, 'search'
         22        SEND_VAL_EX                                              'baz'
         23        SEND_VAL_EX                                              1
         24        DO_FCALL                                      0  $9      
         25        ADD_ARRAY_ELEMENT                                ~7      $9
  180    26        INIT_METHOD_CALL                                         !0, 'lookup'
         27        SEND_VAL_EX                                              'foo'
         28        DO_FCALL                                      0  $10     
         29        ADD_ARRAY_ELEMENT                                ~7      $10
  181    30        INIT_METHOD_CALL                                         !0, 'lookup'
         31        SEND_VAL_EX                                              'bar'
         32        SEND_VAL_EX                                              'de'
         33        SEND_VAL_EX                                              <false>
         34        SEND_VAL_EX                                              5
         35        DO_FCALL                                      0  $11     
         36        ADD_ARRAY_ELEMENT                                ~7      $11
  182    37        INIT_METHOD_CALL                                         !0, 'lookup'
         38        SEND_VAL_EX                                              'baz'
         39        SEND_VAL_EX                                              'za'
         40        SEND_VAL_EX                                              <true>
         41        SEND_VAL_EX                                              20
         42        DO_FCALL                                      0  $12     
         43        ADD_ARRAY_ELEMENT                                ~7      $12
         44        SEND_VAL                                                 ~7
  176    45        DO_ICALL                                                 
  184    46      > RETURN                                                   1

Class Http:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  get
number of ops:  14
compiled vars:  !0 = $url, !1 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        NEW                                              $2      'Response'
          3        INIT_FCALL                                               'json_encode'
          4        INIT_ARRAY                                       ~3      !0, 'url'
          5        ADD_ARRAY_ELEMENT                                ~3      !1, 'params'
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                         $4      
          8        SEND_VAR_NO_REF_EX                                       $4
          9        DO_FCALL                                      0          
         10        VERIFY_RETURN_TYPE                                       $2
         11      > RETURN                                                   $2
   10    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function get

End of class Http.

Class Response:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $response
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   20     3      > RETURN                                                   null

End of function __construct

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

End of function json

End of class Response.

Class Search\Specification:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __invoke
number of ops:  3
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        VERIFY_RETURN_TYPE                                       
          2      > RETURN                                                   null

End of function __invoke

End of class Search\Specification.

Class Search\Name:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   43     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __invoke
number of ops:  7
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   48     1        FETCH_OBJ_R                                      ~1      'name'
          2        INIT_ARRAY                                       ~2      ~1, 'name'
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   50     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function __invoke

End of class Search\Name.

Class Search\Language:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $language
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   61     1        ASSIGN_OBJ                                               'language'
          2        OP_DATA                                                  !0
   62     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __invoke
number of ops:  9
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   67     1        FETCH_OBJ_IS                                     ~1      'language'
          2        COALESCE                                         ~2      ~1
          3        QM_ASSIGN                                        ~2      'en'
          4        INIT_ARRAY                                       ~3      ~2, 'language'
          5        VERIFY_RETURN_TYPE                                       ~3
          6      > RETURN                                                   ~3
   69     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function __invoke

End of class Search\Language.

Class Search\Fuzzy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $fuzzy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   80     1        ASSIGN_OBJ                                               'fuzzy'
          2        OP_DATA                                                  !0
   81     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __invoke
number of ops:  7
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
   86     1        FETCH_OBJ_R                                      ~1      'fuzzy'
          2        INIT_ARRAY                                       ~2      ~1, 'fuzzy'
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   88     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function __invoke

End of class Search\Fuzzy.

Class Search\Limit:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   RECV                                             !0      
   99     1        ASSIGN_OBJ                                               'limit'
          2        OP_DATA                                                  !0
  100     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __invoke
number of ops:  9
compiled vars:  !0 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  102     0  E >   RECV                                             !0      
  105     1        FETCH_OBJ_R                                      ~1      'limit'
          2        JMP_SET                                          ~2      ~1, ->4
          3        QM_ASSIGN                                        ~2      10
          4        INIT_ARRAY                                       ~3      ~2, 'maxRows'
          5        VERIFY_RETURN_TYPE                                       ~3
          6      > RETURN                                                   ~3
  107     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function __invoke

End of class Search\Limit.

Class Api\Searchable:
Function search:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  search
number of ops:  2
compiled vars:  !0 = $criteria
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  115     0  E >   RECV_VARIADIC                                    !0      
          1      > RETURN                                                   null

End of function search

End of class Api\Searchable.

Class Api\Search:
Function search:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  search
number of ops:  18
compiled vars:  !0 = $criteria
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  126     0  E >   RECV_VARIADIC                                    !0      
  128     1        INIT_STATIC_METHOD_CALL                                  'Http', 'get'
          2        FETCH_OBJ_R                                      ~1      'url'
          3        SEND_VAL                                                 ~1
          4        INIT_NS_FCALL_BY_NAME                                    'Api%5Carray_reduce'
  129     5        SEND_VAR_EX                                              !0
  130     6        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          7        SEND_VAL_EX                                              ~2
          8        CHECK_FUNC_ARG                                           
  131     9        FETCH_OBJ_FUNC_ARG                               $3      'defaults'
         10        SEND_FUNC_ARG                                            $3
  128    11        DO_FCALL                                      0  $4      
  131    12        SEND_VAR                                                 $4
  128    13        DO_FCALL                                      0  $5      
  132    14        INIT_METHOD_CALL                                         $5, 'json'
         15        DO_FCALL                                      0  $6      
         16      > RETURN                                                   $6
  133    17*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  Api\{closure}
number of ops:  8
compiled vars:  !0 = $params, !1 = $criteria
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  130     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_DYNAMIC_CALL                                        !1
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        ADD                                              ~3      $2, !0
          6      > RETURN                                                   ~3
          7*     > RETURN                                                   null

End of Dynamic Function 0

End of function search

End of class Api\Search.

Class Controller\Api:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  __construct
number of ops:  4
compiled vars:  !0 = $someApi
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  143     0  E >   RECV                                             !0      
  145     1        ASSIGN_OBJ                                               'api'
          2        OP_DATA                                                  !0
  146     3      > RETURN                                                   null

End of function __construct

Function search:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  search
number of ops:  15
compiled vars:  !0 = $name, !1 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  148     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
  150     2        FETCH_OBJ_R                                      ~2      'api'
          3        INIT_METHOD_CALL                                         ~2, 'search'
  151     4        NEW                                              $3      'Search%5CName'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $3
  152     8        NEW                                              $5      'Search%5CLimit'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        SEND_VAR_NO_REF_EX                                       $5
  150    12        DO_FCALL                                      0  $7      
  152    13      > RETURN                                                   $7
  154    14*     > RETURN                                                   null

End of function search

Function lookup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBiLE
function name:  lookup
number of ops:  25
compiled vars:  !0 = $name, !1 = $language, !2 = $fuzzy, !3 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  156     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
          2        RECV_INIT                                        !2      <const ast>
          3        RECV_INIT                                        !3      <const ast>
  162     4        FETCH_OBJ_R                                      ~4      'api'
          5        INIT_METHOD_CALL                                         ~4, 'search'
  163     6        NEW                                              $5      'Search%5CName'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $5
  164    10        NEW                                              $7      'Search%5CLanguage'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $7
  165    14        NEW                                              $9      'Search%5CFuzzy'
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $9
  166    18        NEW                                              $11     'Search%5CLimit'
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0          
         21        SEND_VAR_NO_REF_EX                                       $11
  162    22        DO_FCALL                                      0  $13     
  166    23      > RETURN                                                   $13
  168    24*     > RETURN                                                   null

End of function lookup

End of class Controller\Api.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.58 ms | 1029 KiB | 17 Q