Skip to content

Remove invalid comma from php code example #8319

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 1 commit into from
Closed

Remove invalid comma from php code example #8319

wants to merge 1 commit into from

Conversation

rouenollivier
Copy link

Remove invalid comma from php code example because it causes a php syntax error

Remove invalid comma from php code example because it causes a php syntax error
@xabbuh
Copy link
Member

xabbuh commented Aug 30, 2017

In fact, there is no problem in even terminating the last element in an array with a comma (and it's the code style used in Symfony). Are you sure that the syntax error was caused by this code?

@PhilETaylor
Copy link
Contributor

@xabbuh While you are correct that there is no problem in terminating the last element in an array with a comma, this is not the case here.

The comma is in the wrong place for it to be in the array. See that it is following a curly brace } and not a bracket )

@javiereguiluz
Copy link
Member

javiereguiluz commented Aug 30, 2017

@PhilETaylor the problem is that this example is a bit complex and the comma looks wrong and out of place ... but I think it's technically correct. If we remove the entire function contents, it looks like this:

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'validation_groups' => function (FormInterface $form) { ... },
    ));
}

In any case, maybe here we shouldn't add the trailing comma. We generally do that, but we don't always do that. For example, some examples in this page: https://github.com/symfony/symfony-docs/blob/master/service_container.rst contain arrays but they don't include the trailing comma.

In short: even if the current example is technically correct, maybe removing the trailing comma makes it easier to understand it.

@PhilETaylor
Copy link
Contributor

indeed you are right, now that I put the code in my ide it's a lot clearer and the PHP syntax is correct, still, best to remove it by merging this anyway like you said :)

@wouterj
Copy link
Member

wouterj commented Aug 30, 2017

I would rather update the other examples to include the trailing comma. We decided that we follow the Symfony Coding Guidelines a couple years ago. Adding the trailing comma for array items is one of the rules in there.

So a 👎 from me. (but this of course doesn't mean I hate your PR, thanks for taking the time to improve the docs!)

@HeahDude
Copy link
Contributor

Closing as we all agree here that should not be changed. Thanks @rouenollivier for trying to improve the docs :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants