diff --git a/components/expression_language/extending.rst b/components/expression_language/extending.rst index 94762110bcd..5f1f743d631 100644 --- a/components/expression_language/extending.rst +++ b/components/expression_language/extending.rst @@ -35,7 +35,7 @@ This method has 3 arguments: $language = new ExpressionLanguage(); $language->register('lowercase', function ($str) { - is_string(%1$s) ? strtolower(%1$s) : %1$s; + return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str); }, function ($arguments, $str) { if (!is_string($str)) { return $str; @@ -69,11 +69,7 @@ Override ``registerFunctions`` to add your own functions:: parent::registerFunctions(); // do not forget to also register core functions $this->register('lowercase', function ($str) { - if (!is_string($str)) { - return $str; - } - - return sprintf('strtolower(%s)', $str); + return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str); }, function ($arguments, $str) { if (!is_string($str)) { return $str;