[PSR-12] Casting variable section

136 views
Skip to first unread message

Georgios Mponos

unread,
Dec 28, 2018, 10:07:21 AM12/28/18
to PHP Framework Interoperability Group
Hello,

I am writing this thread in order to notify you about casting issues that got into my attention. I think that PSR-12 is not dealing with how the casting should be styled


Also one more thing that could be useful is this:


I believe that PSR-12 should deal with spaces inside of cast and spaces before the cast.

Regards,

Alexander Makarov

unread,
Jan 3, 2019, 1:26:18 PM1/3/19
to PHP Framework Interoperability Group
Lowercase and short forms for keywords are covered. Spaces aren't addressed because it is quite controversial. Both space after casting and no-space after casting styles are used widely.

Georgios Mponos

unread,
Jan 3, 2019, 2:28:40 PM1/3/19
to PHP Framework Interoperability Group
Hello Alexander... Mostly I care about cases of space before cast.. (check the doctrine PR) and spaces inside the cast (check the codesniffer PR)..

Do you believe that these two cases could be covered from the new PSR-12.. I undestand that what you mention is indeed controversial.. but the cases that I am referring to are not that much according to my perception.

Georgios Mponos

unread,
Jan 3, 2019, 2:35:00 PM1/3/19
to PHP Framework Interoperability Group
Elaborating further:


case 1:

if ( (bool) $var === true){

}

// although this might be covered from section about if statements

case 2:

$var =(bool)$var1;

// although this might from other section related with assignment of variable...

case 3:
( bool ) $var === true

// I think this is not covered from any section

Τη Παρασκευή, 28 Δεκεμβρίου 2018 - 5:07:21 μ.μ. UTC+2, ο χρήστης Georgios Mponos έγραψε:

Alessandro Lai

unread,
Jan 8, 2019, 7:33:20 AM1/8/19
to PHP Framework Interoperability Group
I agree, spacing before could be required and spacing inside could be forbidden.

Alexander Makarov

unread,
Jan 16, 2019, 4:56:14 AM1/16/19
to PHP Framework Interoperability Group
Agree.

Alexander Makarov

unread,
Jan 16, 2019, 4:56:26 AM1/16/19
to PHP Framework Interoperability Group
I'll pull-request.

Georgios Mponos

unread,
Jan 16, 2019, 7:06:42 AM1/16/19
to PHP Framework Interoperability Group
FYI it needs some extra attention because in case of an `if` statement you do not want a space before.. (at least that's what I think)... or in case of an assignment you need the space before.

if((int)$var) {

}

$var = (int) $var2;

Τη Παρασκευή, 28 Δεκεμβρίου 2018 - 5:07:21 μ.μ. UTC+2, ο χρήστης Georgios Mponos έγραψε:

Alexander Makarov

unread,
Jan 18, 2019, 5:41:12 AM1/18/19
to PHP Framework Interoperability Group
After thinking about it more, spaces before should not be mentioned because these are covered by operators and statements already:

From section 5, control structures:

> - There must not be a space after the opening parenthesis
> - There MUST NOT be a space before the closing parenthesis

From section 6, operators:

> - All binary and ternary (but not unary) operators MUST be preceded and followed by at least
one space

So that leaves us with one addition that is specific for type casting — https://github.com/php-fig/fig-standards/pull/1141

Alexander Makarov

unread,
Jan 21, 2019, 12:58:11 PM1/21/19
to PHP Framework Interoperability Group
Merged. Thank you raising the issue, Georgios.
Reply all
Reply to author
Forward
0 new messages