diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index b07bf8aa51..e6fb891798 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -67,6 +67,7 @@ use function in_array; use function is_array; use function is_object; +use function is_scalar; use function reset; use function spl_object_id; use function sprintf; @@ -1565,7 +1566,19 @@ final public static function getIdHashByIdentifier(array $identifier): string return implode( ' ', - $identifier, + array_map( + static function ($value) { + if (! is_scalar($value) && ! ($value instanceof Stringable)) { + throw new UnexpectedValueException(sprintf( + 'Unexpected identifier value: Expecting scalar or Stringable, got %s.', + get_debug_type($value), + )); + } + + return $value; + }, + $identifier, + ), ); } diff --git a/tests/Tests/ORM/Functional/IdentifierFunctionalTest.php b/tests/Tests/ORM/Functional/IdentifierFunctionalTest.php new file mode 100644 index 0000000000..7f5e4952f5 --- /dev/null +++ b/tests/Tests/ORM/Functional/IdentifierFunctionalTest.php @@ -0,0 +1,26 @@ +useModelSet('cms'); + + parent::setUp(); + } + + public function testIdentifierArrayValue(): void + { + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected identifier value: Expecting scalar or Stringable, got array.'); + $this->_em->find(CmsUser::class, ['id' => ['array']]); + } +}