diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 9d6dd1a..df61635 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -372,6 +372,9 @@ public function attachLibrary($library) { * * @return string|null * The escaped, rendered output, or NULL if there is no valid output. + * + * @throws \Exception + * When passed $string is an object that has no __toString() method. */ public function escapePlaceholder($env, $string) { return '' . $this->escapeFilter($env, $string) . ''; @@ -400,6 +403,9 @@ public function escapePlaceholder($env, $string) { * @return string|null * The escaped, rendered output, or NULL if there is no valid output. * + * @throws \Exception + * When passed $arg is an object that has no __toString() method. + * * @todo Refactor this to keep it in sync with theme_render_and_autoescape() * in https://www.drupal.org/node/2575065 */ @@ -431,7 +437,7 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ elseif (method_exists($arg, '__toString')) { $return = (string) $arg; } - // You can't throw exceptions in the magic PHP __toString methods, see + // You can't throw exceptions in the magic PHP __toString() methods, see // http://php.net/manual/en/language.oop5.magic.php#object.tostring so // we also support a toString method. elseif (method_exists($arg, 'toString')) { @@ -469,7 +475,7 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ /** * Wrapper around render() for twig printed output. * - * If an object is passed that has no __toString method an exception is thrown; + * If an object is passed that has no __toString() method an exception is thrown; * other objects are casted to string. However in the case that the object is an * instance of a Twig_Markup object it is returned directly to support auto * escaping. @@ -483,6 +489,9 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $ * @return mixed * The rendered output or an Twig_Markup object. * + * @throws \Exception + * When passed $arg is an object that has no __toString() method. + * * @see render * @see TwigNodeVisitor */ @@ -509,7 +518,7 @@ public function renderVar($arg) { elseif (method_exists($arg, '__toString')) { return (string) $arg; } - // You can't throw exceptions in the magic PHP __toString methods, see + // You can't throw exceptions in the magic PHP __toString() methods, see // http://php.net/manual/en/language.oop5.magic.php#object.tostring so // we also support a toString method. elseif (method_exists($arg, 'toString')) {