3v4l.org

run code in 300+ 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:  46
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                                               'sprintf'
         13        SEND_VAL                                                 'With+query%3A+%25s%25s'
         14        INIT_FCALL                                               'querymanip'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $12     
         17        INIT_METHOD_CALL                                         $12, 'getTargetUrl'
         18        DO_FCALL                                      0  $13     
         19        SEND_VAR                                                 $13
         20        SEND_VAL                                                 '%0A'
         21        DO_ICALL                                         $14     
         22        ECHO                                                     $14
   32    23        INIT_FCALL                                               'sprintf'
         24        SEND_VAL                                                 'Without+query%3A+%25s%25s'
         25        INIT_FCALL                                               'querymanip'
         26        SEND_VAR                                                 !1
         27        DO_FCALL                                      0  $15     
         28        INIT_METHOD_CALL                                         $15, 'getTargetUrl'
         29        DO_FCALL                                      0  $16     
         30        SEND_VAR                                                 $16
         31        SEND_VAL                                                 '%0A'
         32        DO_ICALL                                         $17     
         33        ECHO                                                     $17
   33    34        INIT_FCALL                                               'sprintf'
         35        SEND_VAL                                                 'Without+question%3A+%25s%25s'
         36        INIT_FCALL                                               'querymanip'
         37        SEND_VAR                                                 !2
         38        DO_FCALL                                      0  $18     
         39        INIT_METHOD_CALL                                         $18, 'getTargetUrl'
         40        DO_FCALL                                      0  $19     
         41        SEND_VAR                                                 $19
         42        SEND_VAL                                                 '%0A'
         43        DO_ICALL                                         $20     
         44        ECHO                                                     $20
         45      > RETURN                                                   1

Function querymanip:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 35
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/XYAX5
function name:  queryManip
number of ops:  42
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        INIT_FCALL                                               'str_contains'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 '%3F'
          7        DO_ICALL                                         $6      
          8      > JMPZ                                                     $6, ->35
   22     9    >   INIT_FCALL                                               'parse_url'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 6
         12        DO_ICALL                                         $7      
         13        JMP_SET                                          ~8      $7, ->15
         14        QM_ASSIGN                                        ~8      ''
         15        ASSIGN                                                   !2, ~8
   23    16        INIT_FCALL                                               'parse_str'
         17        SEND_VAR                                                 !2
         18        SEND_REF                                                 !3
         19        DO_ICALL                                                 
   24    20        INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !1
         22        SEND_VAL                                                 0
         23        INIT_FCALL                                               'strpos'
         24        SEND_VAR                                                 !1
         25        SEND_VAL                                                 '%3F'
         26        DO_ICALL                                         $11     
         27        SEND_VAR                                                 $11
         28        DO_ICALL                                         $12     
         29        CONCAT                                           ~13     $12, '%3F'
         30        INIT_FCALL                                               'http_build_query'
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $14     
         33        CONCAT                                           ~15     ~13, $14
         34        ASSIGN                                                   !1, ~15
   26    35    >   INIT_METHOD_CALL                                         !0, 'setTargetUrl'
         36        SEND_VAR_EX                                              !1
         37        DO_FCALL                                      0          
   27    38        VERIFY_RETURN_TYPE                                       !0
         39      > RETURN                                                   !0
   28    40*       VERIFY_RETURN_TYPE                                       
         41*     > 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.0.0


preferences:
146.7 ms | 1454 KiB | 23 Q