diff --git a/core/modules/color/color.module b/core/modules/color/color.module
index 8a118d7cd0046c73d7c31ebaaa644a3f94585277..eb36f30cafaa03acf9c5e588334bfb747e4499da 100644
--- a/core/modules/color/color.module
+++ b/core/modules/color/color.module
@@ -334,7 +334,7 @@ function color_palette_color_value($element, $input, FormStateInterface $form_st
  *   isn't.
  */
 function color_valid_hexadecimal_string($color) {
-  return preg_match('/^#([a-f0-9]{3}){1,2}$/iD', $color);
+  return (bool) preg_match('/^#([a-f0-9]{3}){1,2}$/iD', $color);
 }
 
 /**
diff --git a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
index 0359aa01cdd3856b6545980c9669c37cf978f208..318e0ca9a75f807dbc64858c713e92dfa6a2f12f 100644
--- a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
@@ -211,7 +211,7 @@ public function commentExists(CommentInterface $comment = NULL, $reply = FALSE)
    *   Contact info is available.
    */
   public function commentContactInfoAvailable() {
-    return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
+    return (bool) preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
   }
 
   /**