From 3eaaf26ab241aa6635974a0f788c833096335799 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 12 Aug 2014 15:04:39 +0200 Subject: [PATCH] Fixed the code snippets for the expression language functions --- components/expression_language/extending.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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;