rfc:replace_parse_url
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:replace_parse_url [2016/10/04 15:03] – bp1222 | rfc:replace_parse_url [2017/09/22 13:28] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Replace parse_url() | + | ====== PHP RFC: Create RFC Compliant URL Parser |
- | * Version: 0.1 | + | * Version: 0.3 |
- | * Date: 2016-10-03 | + | * Date: 2016-10-04 |
* Author: David Walker (dave@mudsite.com) | * Author: David Walker (dave@mudsite.com) | ||
* Proposed version: PHP 7.2+ | * Proposed version: PHP 7.2+ | ||
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC came about for an attempt to resolve [[https:// | + | This RFC came about for an attempt to resolve [[https:// |
- | The RFC proposes replacing the current implementation of '' | + | The current implementation of '' |
- | ===== Reasoning ===== | + | So, this RFC proposes creating a new parser that adheres to the two RFC's. In doing so, if PHP is compiled |
- | The bug described an issue where using '' | + | |
+ | ===== Proposal ===== | ||
<file php> | <file php> | ||
<?php | <?php | ||
- | var_dump(parse_url(" | ||
- | var_dump(parse_url(" | ||
- | /* Outputs: | + | class URL { |
- | string(9) "127.0.0.1" | + | public function |
- | NULL | + | |
- | */ | + | |
- | </ | + | * $input - The string |
+ | * $base - (optional) If $url is relative, this is what it is relative to | ||
+ | * $encoding_override - (optional) we assume $url is a UTF-8 encoded string, you may change it here | ||
+ | * $url - (optional) A URL object that should be modified by the parsing of $input. The return value will be this variable as well | ||
+ | * $state_override - (optional) begin parting the $input from a specific state. | ||
+ | | ||
+ | | ||
+ | |||
+ | public function getScheme() : ?string; | ||
+ | public function getUsername() : ?string; | ||
+ | public function getPassword() : ?string; | ||
+ | public function getHostname() : ?string; | ||
+ | public function getPort() : ?int; | ||
+ | public function getPath() : ?string; | ||
+ | public function getQuery() : ?string; | ||
+ | public function getFragment() : ?string; | ||
+ | |||
+ | public function getAll() : array; | ||
+ | } | ||
- | While we may agree the that former line is sensible and maybe expected; the behavior is contrary to how the RFC defines parsing a URI. To be compliant it should parse as a single PATH element '' | ||
- | |||
- | The bug does state that the parsing difference between IPv4 address and IPv6 addresses are handled differently (in the sense that the IPv4 parsing isn't standards compliant). | ||
- | |||
- | An accurate example of standards compliant parsing: | ||
- | <file php> | ||
- | <?php | ||
- | var_dump(parse_url(" | ||
- | var_dump(parse_url(" | ||
- | |||
- | /* Outputs: | ||
- | string(12) " | ||
- | NULL | ||
- | */ | ||
</ | </ | ||
- | |||
- | With that in mind, a correct example of parsing URI's to acquire the host portion, per the bugs request would look similar to the following: | ||
- | <file php> | ||
- | <?php | ||
- | var_dump(parse_url(" | ||
- | var_dump(parse_url(" | ||
- | |||
- | var_dump(parse_url("// | ||
- | var_dump(parse_url("// | ||
- | |||
- | /* Outputs: | ||
- | NULL | ||
- | NULL | ||
- | string(9) " | ||
- | string(5) " | ||
- | */ | ||
- | </ | ||
- | |||
- | ===== Proposal ===== | ||
- | The proposal of this RFC is two fold. One, replace the current parser used for '' | ||
- | |||
- | The function can return | ||
- | * An array consisting of each component of the URI found. | ||
- | * A string|int of the component requested by the 2nd argument | ||
- | * NULL when we can not parse the URI, or, the component request contains no value | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Many of the tests that were developed for the current implementation of '' | + | None |
- | + | ||
- | This function will no longer return false. | + | |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | standard | + | standard |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Make sure there are no open issues when the vote starts! | + | * Deprecate '' |
+ | * Should '' | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Vote to replace '' | ||
Requires 2/3 | Requires 2/3 | ||
Line 90: | Line 65: | ||
===== References ===== | ===== References ===== | ||
- | PR with working Implementation: |
rfc/replace_parse_url.txt · Last modified: 2021/03/27 14:57 by ilutov