Skip to content

Commit

Permalink
Fix method_exist() calls throwing \TypeError exceptions on non-st…
Browse files Browse the repository at this point in the history
…ring|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.
  • Loading branch information
Ayesh committed Jun 27, 2020
1 parent 4e99d71 commit bf6b34b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit bf6b34b

Please sign in to comment.