diff --git a/core/lib/Drupal/Core/Utility/Token.php b/core/lib/Drupal/Core/Utility/Token.php
index d03d645..e53bc3c 100644
--- a/core/lib/Drupal/Core/Utility/Token.php
+++ b/core/lib/Drupal/Core/Utility/Token.php
@@ -127,11 +127,12 @@ public function __construct(ModuleHandlerInterface $module_handler, CacheBackend
    *   replacement process. Supported options are:
    *   - langcode: A language code to be used when generating locale-sensitive
    *     tokens.
-   *   - callback: A callback function that will be used to post-process the
-   *     array of token replacements after they are generated. For example, a
-   *     module using tokens in a text-only email might provide a callback to
-   *     strip HTML entities from token values before they are inserted into the
-   *     final text.
+   *   - callback: A callable that will be used to post-process the array of
+   *     token replacements after they are generated. For example, a module
+   *     using tokens in a text-only email might provide a callback to strip
+   *     HTML entities from token values before they are inserted into the
+   *     final text. The callback receives the existing replacements, the data,
+   *     and the options as parameters. It must return an array of replacements.
    *   - clear: A boolean flag indicating that tokens should be removed from the
    *     final text if no replacement value can be generated.
    *   - sanitize: A boolean flag indicating that tokens should be sanitized for
@@ -160,8 +161,8 @@ public function replace($text, array $data = array(), array $options = array())
 
     // Optionally alter the list of replacement values.
     if (!empty($options['callback'])) {
-      $function = $options['callback'];
-      $function($replacements, $data, $options);
+      $callback = $options['callback'];
+      $replacements = call_user_func($callback, $replacements, $data, $options);
     }
 
     $tokens = array_keys($replacements);
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 2253d1c..6ddfca7 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1072,7 +1072,7 @@ function user_mail($key, &$message, $params) {
  * some additional tokens that can be used in email messages generated by
  * user_mail().
  *
- * @param $replacements
+ * @param array $replacements
  *   An associative array variable containing mappings from token names to
  *   values (for use with strtr()).
  * @param $data
@@ -1083,12 +1083,16 @@ function user_mail($key, &$message, $params) {
  *   - pass: The hashed account login password.
  * @param $options
  *   Unused parameter required by \Drupal\Core\Utility\Token::replace().
+ *
+ * @return array
  */
-function user_mail_tokens(&$replacements, $data, $options) {
+function user_mail_tokens(array $replacements, $data, $options) {
   if (isset($data['user'])) {
     $replacements['[user:one-time-login-url]'] = user_pass_reset_url($data['user'], $options);
     $replacements['[user:cancel-url]'] = user_cancel_url($data['user'], $options);
   }
+
+  return $replacements;
 }
 
 /*** Administrative features ***********************************************/
