Skip to content

Commit 4629d8b

Browse files
committed
bug #4116 Fixed the code snippets for the expression language functions (stof)
This PR was merged into the 2.4 branch. Discussion ---------- Fixed the code snippets for the expression language functions | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.4+ | Fixed tickets | n/a The compilation callable was broken for the example of the lowercase function (in 2 different ways in the different snippet as the first one was attempted to be fixed in #3771 but my comment asking to remove the return statement inside the compiled expression was misunderstood and the other return statement returning the compiled expression was removed as well.). Commits ------- 3eaaf26 Fixed the code snippets for the expression language functions
2 parents 1f14a0e + 3eaaf26 commit 4629d8b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

Diff for: components/expression_language/extending.rst

+2-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This method has 3 arguments:
3535
3636
$language = new ExpressionLanguage();
3737
$language->register('lowercase', function ($str) {
38-
is_string(%1$s) ? strtolower(%1$s) : %1$s;
38+
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str);
3939
}, function ($arguments, $str) {
4040
if (!is_string($str)) {
4141
return $str;
@@ -69,11 +69,7 @@ Override ``registerFunctions`` to add your own functions::
6969
parent::registerFunctions(); // do not forget to also register core functions
7070

7171
$this->register('lowercase', function ($str) {
72-
if (!is_string($str)) {
73-
return $str;
74-
}
75-
76-
return sprintf('strtolower(%s)', $str);
72+
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str);
7773
}, function ($arguments, $str) {
7874
if (!is_string($str)) {
7975
return $str;

0 commit comments

Comments
 (0)