8000 Fix function example in expression language component by raulfraile · Pull Request #3771 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Fix function example in expression language component #3771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Next Next commit
Fix function example in expression language component
The is_string check needs to be part of the runtime code, not of the compilation code, because it needs to check that the argument is a string, not the compiled code to access it (which is always a string as it is source code
  • Loading branch information
raulfraile committed Apr 7, 2014
commit bc673f3907f64d2946e75cf732ccf79866231f78
6 changes: 1 addition & 5 deletions components/expression_language/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ This method has 3 arguments:

$language = new ExpressionLanguage();
$language->register('lowercase', function ($str) {
if (!is_string($str)) {
return $str;
}

return sprintf('strtolower(%s)', $str);
return sprintf('$result = (is_string(%1$s)) ? strtolower(%1$s) : %1$s; return $result;', $str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't put a return in the compiled expression code. It should simply be (is_string(%1$s) ? strtolower(%1$s) : %1$s)

}, function ($arguments, $str) {
if (!is_string($str)) {
return $str;
Expand Down
0