Skip to content
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

Remove section in CGL about assignments in conditions #705

Conversation

sypets
Copy link
Contributor

@sypets sypets commented Dec 28, 2019

The recommendation to not use assignments in condition and add
extra parenthethese does not reflect current practice in core
and in newer examples in documentation.

In the docs, it said:

Assignment in conditions should be avoided. However if it makes sense to do an assignment in a condition, it should be surrounded by the extra pair of brackets. Example:

if (($fields = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
// Do something
}

see https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/CodingGuidelines/CglPhp/PhpFileFormatting/PhpSyntaxFormatting.html#conditions

But, Assignments in condition are used in abundance in the core and in newer examples, e.g. doctrine-dbal:

while ($row = $statement->fetch()) {
// Do something useful with that single $row
}

https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/Statement/Index.html

Releases: master, 9.5

@sypets sypets added decision required help wanted Request help for solving this issue / PR by others question labels Mar 15, 2020
The recommendation to not use assignments in condition and add
extra parenthethese does not reflect current practice in core
and in newer examples in documentation.

Releases: master, 9.5
@sypets sypets force-pushed the sypets/cgl-remove-no-assignments-in-condition branch from b797a52 to 6d0d5f1 Compare March 15, 2020 16:00
@lolli42
Copy link
Contributor

lolli42 commented Sep 1, 2020

Yes, sometimes assignments in conditions are useful.

@lolli42 lolli42 merged commit 01557e4 into TYPO3-Documentation:master Sep 1, 2020
lolli42 pushed a commit that referenced this pull request Sep 1, 2020
The recommendation to not use assignments in condition and add
extra parenthethese does not reflect current practice in core
and in newer examples in documentation.

Releases: master, 10.4, 9.5
lolli42 pushed a commit that referenced this pull request Sep 1, 2020
The recommendation to not use assignments in condition and add
extra parenthethese does not reflect current practice in core
and in newer examples in documentation.

Releases: master, 10.4, 9.5
@jonaseberle jonaseberle mentioned this pull request Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision required help wanted Request help for solving this issue / PR by others question
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants