thephpleague / uri-schemes

Collection of URI Immutable Value Objects
https://uri.thephpleague.com/schemes/
MIT License
216 stars 7 forks source link

League\Uri\AbstractUri::__set_state throws exception when user_info is null #16

Closed downace closed 5 years ago

downace commented 6 years ago

Issue summary

var_exporting League\Uri\Http without auth info outputs code where user_info is null. This code leads to TypeError.

System informations

Information Description
League\Uri version 5.3.0
PHP/HHVM version 7.2.7
OS Platform Linux 4.15.0-30 x86_64

Standalone code, or other way to reproduce the problem

$uri = \League\Uri\Http::createFromString('http://example.test');
$exported = var_export($uri, true);
$uri = eval("return $exported;"); // just for demonstration
var_dump($uri);

Expected result

class League\Uri\Http#4 (9) {
  protected $scheme =>
  string(4) "http"
  protected $user_info =>
  NULL
  protected $host =>
  string(12) "example.test"
  protected $port =>
  NULL
  protected $authority =>
  string(12) "example.test"
  protected $path =>
  string(0) ""
  protected $query =>
  NULL
  protected $fragment =>
  NULL
  protected $uri =>
  NULL
}

Actual result

Fatal error: Uncaught TypeError: explode() expects parameter 2 to be string, null given in /var/www/html/vendor/league/uri-schemes/src/AbstractUri.php on line 140

TypeError: explode() expects parameter 2 to be string, null given in /var/www/html/vendor/league/uri-schemes/src/AbstractUri.php on line 140

Call Stack:
    0.0001     387904   1. {main}() /usr/src/scratches/scratch_312.php:0
    0.0346    5488296   2. eval('return League\Uri\Http::__set_state(array(
   'scheme' => 'http',
   'user_info' => NULL,
   'host' => 'example.test',
   'port' => NULL,
   'authority' => 'example.test',
   'path' => '',
   'query' => NULL,
   'fragment' => NULL,
   'uri' => NULL,
));') /usr/src/scratches/scratch_312.php:9
    0.0346    5488296   3. League\Uri\AbstractUri::__set_state() /usr/src/scratches/scratch_312.php(9) : eval()'d code:2
    0.0346    5488296   4. explode() /var/www/html/vendor/league/uri-schemes/src/AbstractUri.php:140
nyamsprod commented 6 years ago

@downace thanks for reporting the issue the related package is being fixed. A bugfix release may be released next week or the week after.

nyamsprod commented 5 years ago

the fix has been released for a while 😄