Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request::encodeUrl breaks with PHP 7.4 and ports in host name #156

Open
EdgarWahn opened this issue Dec 22, 2021 · 3 comments
Open

Request::encodeUrl breaks with PHP 7.4 and ports in host name #156

EdgarWahn opened this issue Dec 22, 2021 · 3 comments

Comments

@EdgarWahn
Copy link

EdgarWahn commented Dec 22, 2021

encodeUrl breaks in

    if ($port && $port[0] !== ':') {
        $port = ':' . $port;
    }

with "Notice: Trying to access array offset on value of type int".

Modifying the if query to honor the variable type seems to help.

if ($port && ((gettype($port) == "string" && $port[0] !== ':') || gettype($port) == "integer")) {
$port = ':' . $port;
}

I don't have cloned the project and I am currently very short in time, can someone please fix this issue and make an update available to composer?

Kind regards and have a nice Xmas.

Reproduce:

`<?php
$url_parsed = array (
'scheme' => 'http',
'host' => 'localhost',
'port' => 10003,
'path' => '/some/path',
);

$port = (isset($url_parsed['port']) ? $url_parsed['port'] : null);

// breaks
if ($port && $port[0] !== ':') {
$port = ':' . $port;
}

// seems to work
if ($port && ((gettype($port) == "string" && $port[0] !== ':') || gettype($port) == "integer")) {
$port = ':' . $port;
}

var_export($port);
`

@ennorehling
Copy link

I just noticed the same issue. The problem appears to be that parse_url returns the port as an int, not a string, at least in PHP 7.3 and 7.4 - did this behavior change at any time? There is some mention in the PHP core changelog of a bug where port is 0, maybe the extra check was meant to address that?

The docs for parse_url say:

If the component parameter is specified, parse_url() returns a string (or an integer, in the case of PHP_URL_PORT) instead of an array.
It says nothing about the components of the array, but it's reasonable to expect that the type will still be an integer when asking for all components instead of only the port. I think the breaking array check can be safely removed.

@ennorehling
Copy link

ennorehling commented Jan 17, 2022

This appear similar to #143 which is said to be fixed with 3.0,5 or dev-master, but a) composer cannot find a 3.0.5, and b) dev-master still fails, and looks unchanged.

@ennorehling
Copy link

The difference between PHP 7.3 and 7.4 is stricter typing: PHP 7.3 did not print a notice for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants