3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Response { public function __construct(protected $targetUrl = ''){} public function getTargetUrl(): string { return $this->targetUrl; } public function setTargetUrl(string $target_url): void { $this->targetUrl = $target_url; } } $withQuery = new Response('https://example.com?foo=bar'); $withoutQuery = new Response('https://example.com?'); $withoutQuestion = new Response('https://example.com'); function queryManip(Response $response): Response { // The 'destination' parameter should remain in the query but be // unused by the target_url. $target_url = $response->getTargetUrl(); if (str_contains($target_url, '?')) { $query_string = parse_url($target_url, PHP_URL_QUERY) ?: ''; parse_str($query_string, $query); $target_url = substr($target_url, 0, strpos($target_url, '?')) . '?' . http_build_query($query); } $response->setTargetUrl($target_url); return $response; } echo sprintf('With query: %s%s', queryManip($withQuery)->getTargetUrl(), \PHP_EOL); echo sprintf('Without query: %s%s', queryManip($withoutQuery)->getTargetUrl(), \PHP_EOL); echo sprintf('Without question: %s%s', queryManip($withoutQuestion)->getTargetUrl(), \PHP_EOL);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYAX5
function name:  (null)
number of ops:  40
compiled vars:  !0 = $withQuery, !1 = $withoutQuery, !2 = $withoutQuestion
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   NEW                                                  $3      'Response'
          1        SEND_VAL_EX                                                  'https%3A%2F%2Fexample.com%3Ffoo%3Dbar'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $3
   14     4        NEW                                                  $6      'Response'
          5        SEND_VAL_EX                                                  'https%3A%2F%2Fexample.com%3F'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !1, $6
   15     8        NEW                                                  $9      'Response'
          9        SEND_VAL_EX                                                  'https%3A%2F%2Fexample.com'
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !2, $9
   31    12        INIT_FCALL                                                   'querymanip'
         13        SEND_VAR                                                     !0
         14        DO_FCALL                                          0  $12     
         15        INIT_METHOD_CALL                                             $12, 'getTargetUrl'
         16        DO_FCALL                                          0  $13     
         17        ROPE_INIT                                         3  ~15     'With+query%3A+'
         18        ROPE_ADD                                          1  ~15     ~15, $13
         19        ROPE_END                                          2  ~14     ~15, '%0A'
         20        ECHO                                                         ~14
   32    21        INIT_FCALL                                                   'querymanip'
         22        SEND_VAR                                                     !1
         23        DO_FCALL                                          0  $17     
         24        INIT_METHOD_CALL                                             $17, 'getTargetUrl'
         25        DO_FCALL                                          0  $18     
         26        ROPE_INIT                                         3  ~20     'Without+query%3A+'
         27        ROPE_ADD                                          1  ~20     ~20, $18
         28        ROPE_END                                          2  ~19     ~20, '%0A'
         29        ECHO                                                         ~19
   33    30        INIT_FCALL                                                   'querymanip'
         31        SEND_VAR                                                     !2
         32        DO_FCALL                                          0  $22     
         33        INIT_METHOD_CALL                                             $22, 'getTargetUrl'
         34        DO_FCALL                                          0  $23     
         35        ROPE_INIT                                         3  ~25     'Without+question%3A+'
         36        ROPE_ADD                                          1  ~25     ~25, $23
         37        ROPE_END                                          2  ~24     ~25, '%0A'
         38        ECHO                                                         ~24
         39      > RETURN                                                       1

Function querymanip:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/XYAX5
function name:  queryManip
number of ops:  33
compiled vars:  !0 = $response, !1 = $target_url, !2 = $query_string, !3 = $query
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
   20     1        INIT_METHOD_CALL                                             !0, 'getTargetUrl'
          2        DO_FCALL                                          0  $4      
          3        ASSIGN                                                       !1, $4
   21     4        FRAMELESS_ICALL_2                str_contains        ~6      !1, '%3F'
          5      > JMPZ                                                         ~6, ->26
   22     6    >   INIT_FCALL                                                   'parse_url'
          7        SEND_VAR                                                     !1
          8        SEND_VAL                                                     6
          9        DO_ICALL                                             $7      
         10        JMP_SET                                              ~8      $7, ->12
         11        QM_ASSIGN                                            ~8      ''
         12        ASSIGN                                                       !2, ~8
   23    13        INIT_FCALL                                                   'parse_str'
         14        SEND_VAR                                                     !2
         15        SEND_REF                                                     !3
         16        DO_ICALL                                                     
   24    17        FRAMELESS_ICALL_2                strpos              ~11     !1, '%3F'
         18        FRAMELESS_ICALL_3                substr              ~12     !1, 0
         19        OP_DATA                                                      ~11
         20        CONCAT                                               ~13     ~12, '%3F'
         21        INIT_FCALL                                                   'http_build_query'
         22        SEND_VAR                                                     !3
         23        DO_ICALL                                             $14     
         24        CONCAT                                               ~15     ~13, $14
         25        ASSIGN                                                       !1, ~15
   26    26    >   INIT_METHOD_CALL                                             !0, 'setTargetUrl'
         27        SEND_VAR_EX                                                  !1
         28        DO_FCALL                                          0          
   27    29        VERIFY_RETURN_TYPE                                           !0
         30      > RETURN                                                       !0
   28    31*       VERIFY_RETURN_TYPE                                           
         32*     > RETURN                                                       null

End of function querymanip

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

End of function __construct

Function gettargeturl:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYAX5
function name:  getTargetUrl
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   FETCH_OBJ_R                                          ~0      'targetUrl'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
    7     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function gettargeturl

Function settargeturl:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYAX5
function name:  setTargetUrl
number of ops:  4
compiled vars:  !0 = $target_url
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
    9     1        ASSIGN_OBJ                                                   'targetUrl'
          2        OP_DATA                                                      !0
   10     3      > RETURN                                                       null

End of function settargeturl

End of class Response.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.1 ms | 492 KiB | 13 Q