Skip to content

Spaces in type casting #35

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
dmotitsk opened this issue Jul 20, 2022 · 7 comments · Fixed by #40
Closed

Spaces in type casting #35

dmotitsk opened this issue Jul 20, 2022 · 7 comments · Fixed by #40

Comments

@dmotitsk
Copy link

Are there any requirements regarding spaces in type casting? There is the requirement:

Type casting operators MUST NOT have any space within the parentheses

But what about the space between the type and the expression? I.e.

$intValue = (int) $input;

or

$intValue = (int)$input;

@samdark
Copy link
Member

samdark commented Jul 20, 2022

Currently there's no requirement for it.

@vjik
Copy link
Contributor

vjik commented Aug 11, 2022

Maybe create this requirement?

(int) $input looks good.

@samdark
Copy link
Member

samdark commented Aug 11, 2022

@Crell, @KorvinSzanto thoughts?

@Crell
Copy link
Collaborator

Crell commented Aug 11, 2022

I've only ever seen it without a space: (int)$x.

@guvra
Copy link

guvra commented Aug 11, 2022

I've only ever seen it without a space: (int)$x.

php-cs-fixer adds a space by default: https://cs.symfony.com/doc/rules/cast_notation/cast_spaces.html.
Both laravel and symfony use a single space between cast and variable.

@KorvinSzanto
Copy link
Contributor

PSR-12, Laminas, and the PHP docs all also add spaces. I can't really think of a good reason to omit this so I'd be okay with adding this for typecasts. Something like

Typecasts MUST be separated from the variable they are operating on by exactly one space.

@Crell
Copy link
Collaborator

Crell commented Aug 30, 2022

If that's the de facto consensus, I don't have a strong argument to not follow it on this one. Sounds like we need a PR.

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

Successfully merging a pull request may close this issue.

6 participants