1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
From: James Valleroy <jvalleroy@mailbox.org>
Date: Sat, 26 Dec 2020 21:33:11 -0500
Subject: Slim/Http: Handle strict type checking in method_exists for PHP 8.0
These functions accept either strings or objects that can convert to
strings. If the parameter is not a string, check if it is an object
before calling method_exists.
---
Slim/Http/Response.php | 3 ++-
Slim/Http/Uri.php | 12 ++++++++----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/Slim/Http/Response.php b/Slim/Http/Response.php
index 8ad475d..f156f70 100644
--- a/Slim/Http/Response.php
+++ b/Slim/Http/Response.php
@@ -190,7 +190,8 @@ class Response extends Message implements ResponseInterface
{
$code = $this->filterStatus($code);
- if (!is_string($reasonPhrase) && !method_exists($reasonPhrase, '__toString')) {
+ if (!is_string($reasonPhrase) &&
+ (!is_object($reasonPhrase) || !method_exists($reasonPhrase, '__toString'))) {
throw new InvalidArgumentException('ReasonPhrase must be a string');
}
diff --git a/Slim/Http/Uri.php b/Slim/Http/Uri.php
index 5c67ec8..57658bb 100644
--- a/Slim/Http/Uri.php
+++ b/Slim/Http/Uri.php
@@ -134,7 +134,8 @@ class Uri implements UriInterface
*/
public static function createFromString($uri)
{
- if (!is_string($uri) && !method_exists($uri, '__toString')) {
+ if (!is_string($uri) &&
+ (!is_object($uri) || !method_exists($uri, '__toString'))) {
throw new InvalidArgumentException('Uri must be a string');
}
@@ -294,7 +295,8 @@ class Uri implements UriInterface
'http' => true,
];
- if (!is_string($scheme) && !method_exists($scheme, '__toString')) {
+ if (!is_string($scheme) &&
+ (!is_object($scheme) || !method_exists($scheme, '__toString'))) {
throw new InvalidArgumentException('Uri scheme must be a string');
}
@@ -694,7 +696,8 @@ class Uri implements UriInterface
*/
public function withQuery($query)
{
- if (!is_string($query) && !method_exists($query, '__toString')) {
+ if (!is_string($query) &&
+ (!is_object($query) || !method_exists($query, '__toString'))) {
throw new InvalidArgumentException('Uri query must be a string');
}
$query = ltrim((string)$query, '?');
@@ -761,7 +764,8 @@ class Uri implements UriInterface
*/
public function withFragment($fragment)
{
- if (!is_string($fragment) && !method_exists($fragment, '__toString')) {
+ if (!is_string($fragment) &&
+ (!is_object($fragment) || !method_exists($fragment, '__toString'))) {
throw new InvalidArgumentException('Uri fragment must be a string');
}
$fragment = ltrim((string)$fragment, '#');
|