From bf6b34bb8f1acd7e38a1e99e25514cfb04ee05cc Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne <ayesh@ayesh.me> Date: Sun, 28 Jun 2020 00:26:46 +0700 Subject: [PATCH 1/2] Fix `method_exist()` calls throwing `\TypeError` exceptions on non-string|object PHP 8 throws `\TypeError` and `\ValueError` exceptions in internal functions (including `method_exists()`) when it encounters an invalid value. For `method_exists`, it expects `string|object`. See https://php.watch/versions/8.0/internal-function-exceptions `Assert::methodExists()` and `Assert::methodNotExists()` are updated to make sure the provided argument is string|object before calling `method_exist()` to avoid PHP 8 `\TypeError` exceptions. --- src/Assert.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Assert.php b/src/Assert.php index dd1ffe6e..b28e1784 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1620,7 +1620,7 @@ public static function propertyNotExists($classOrObject, $property, $message = ' */ public static function methodExists($classOrObject, $method, $message = '') { - if (!\method_exists($classOrObject, $method)) { + if (!(\is_string($classOrObject) || \is_object($classOrObject)) || !\method_exists($classOrObject, $method)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the method %s to exist.', static::valueToString($method) @@ -1640,7 +1640,7 @@ public static function methodExists($classOrObject, $method, $message = '') */ public static function methodNotExists($classOrObject, $method, $message = '') { - if (\method_exists($classOrObject, $method)) { + if ((\is_string($classOrObject) || \is_object($classOrObject)) && \method_exists($classOrObject, $method)) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected the method %s to not exist.', static::valueToString($method) From 8d99260b1914974734d7588f5a6a289e3f81c065 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne <ayesh@ayesh.me> Date: Sun, 28 Jun 2020 00:46:25 +0700 Subject: [PATCH 2/2] composer.json: Allow PHP 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bb478f57..2e609b63 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^5.3.3 || ^7.0", + "php": "^5.3.3 || ^7.0 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, "require-dev": {