8000 [ExpressionLanguage] Add missing argument in example code by kevin-verschaeve · Pull Request #9764 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[ExpressionLanguage] Add missing argument in example code #9764

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

Conversation

kevin-verschaeve
Copy link
Contributor

Like the docs says just below

Both the compiler and evaluator are passed an arguments variable as their first argument

The example was missing the $arguments for the compiler method

@javiereguiluz
Copy link
Member

It's hard for me to review this because there are no many examples of register() ... neither in community blog posts or our own code, tests and examples. In fact, this is the only occurrence in tests:

    protected function registerFunctions()
    {
        $this->register('constant', function ($constant) {
            return sprintf('constant(%s)', $constant);
        }, function (array $values, $constant) {
            return constant($constant);
        });
    }

As you can see, the first anonymous function passed to register() only takes one argument 😕

@javiereguiluz javiereguiluz added the help wanted Issues and PRs which are looking for volunteers to complete them. label May 24, 2018
@wouterj
Copy link
Member
wouterj commented May 24, 2018

@javiereguiluz All ExpressionFunction instances in Symfony source can be used here.

If we look at one such example:

            new ExpressionFunction('is_granted', function ($attributes, $object = 'null') {
                return sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object);
            }, function (array $variables, $attributes, $object = null) {
                return $variables['auth_checker']->isGranted($attributes, $object);
            }),

It is clear that the compiler doesn't get the arguments. It has to reference these as normal PHP variables.

This is also logical, as the compiler transforms an expression to PHP code and this PHP code will be run later on with some variables (Arguments). These arguments are not yet known when the compiler function is run, so the arguments cannot be provided as argument to the compiler function.

So instead of update the code, can you please update the incorrect description below? Thanks for finding & trying to fix bugs in the Symfony docs!

@javiereguiluz javiereguiluz modified the milestones: 2.7, 2.8 May 28, 2018
@javiereguiluz
Copy link
Member

We finally made the changes requested by Wouter, so we can merge here. Thanks!

javiereguiluz added a commit that referenced this pull request Jun 27, 2018
… (kevin-verschaeve, javiereguiluz)

This PR was submitted for the 2.7 branch but it was merged into the 2.8 branch instead (closes #9764).

Discussion
----------

[ExpressionLanguage] Add missing argument in example code

Like the docs says just below
>  Both the compiler and evaluator are passed an arguments variable as their first argument

The example was missing the `$arguments` for the `compiler` method

Commits
-------

280c23c Reword
3ce4089 [ExpressionLanguage] Add missing argument in example code
@kevin-verschaeve
Copy link
Contributor Author

Thanks Javier :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ExpressionLanguage help wanted Issues and PRs which are looking for volunteers to complete them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0