-
Notifications
You must be signed in to change notification settings - Fork 25
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
New PHP syntax worth considering #3
Comments
Serializable is deprecated (see https://wiki.php.net/rfc/phase_out_serializable) and is meant as a compatibility layer for old implementations.
For composite types, no spaces IMHO, especially when mixing union and intersection types (soon inc.) having loads of spaces is going to be detrimental to readability IMHO. |
I wanted to include anything not removed just in case
👍 We already require folks use
I'm not so sure on this one, PSR-12 currently prefers spaces around other binary operators and other languages that have similar syntax also tend to prefer the spaces. 1 2 3 I agree these declarations will get harder to read as they get longer especially since we don't have a great way to make larger union types portable like function foo():
null |
SomeReallyLongClassName |
SomeReallyLongOtherClassNameInterface |
SomeReallyLongOtherOtherClassNameInterface
{
return 1;
} Footnotes |
In regard to multiline declaration, IMHO we should suggest to put the operators at the start of the line, so it makes immediately clear that there's a continued declaration (or operation, in other contexts like with function foo():
null
| SomeReallyLongClassName
| SomeReallyLongOtherClassNameInterface
| SomeReallyLongOtherOtherClassNameInterface
{
return 1;
} |
From what I've seen, union types are generally written without spaces right now. At least that's what TYPO3 has been doing as we add types for v12. IF going multiline, I agree the | should be at the start, as is typical for other similar constructs. |
Looking at Typescript, union and intersection type declarations include spaces around operators (see https://github.com/microsoft/TypeScript/blob/main/src/lib/es5.d.ts#L174 for example). |
PR for short closures: #17 |
PR for trailing commas: #18 |
PR for typed properties and readonly: #19 |
PR for attributes: #26 |
Things I think we can be silent on:
|
PR for FCC: #27 |
I don't think there is a generally applicable guideline other than “yes, please make use of it”. The “correct” grouping depends on a context:
|
Handles readonly classes: #41 |
I'm going to argue that CPP is already adequately covered by existing rules, so nothing new needs to be said. Named arguments are here: #42 |
Nested ternaries: #43 |
OK, I have gone through and Everything else now has an active PR. Discussion on those PRs. 😄 |
I'll call this done at this point. |
I've gone through the PHP versions since 7.3 which was the most recently released when PSR-12 was accepted and gathered a list of syntax that we may want to cover in this PER. This list is likely incomplete so please add a comment if there's more I should add.
PHP 7.3: https://www.php.net/manual/en/migration73.php
Array destructuring: https://3v4l.org/85FjDfoo(1, 2, 3,)
PHP 7.4: https://www.php.net/manual/en/migration74.php
public int $foo;
fn(int $foo) => $foo * 2
Numeric literal separator:$int = 1_000_000;
__serialize
and__unserialize
vs usingSerializable
Nested ternaries require parenthesis in some situations post 7.4, we should consider usingSHOULD NOT
for nested ternaries.PHP 8.0: https://www.php.net/manual/en/migration80.php
foo(1, c: 2)
https://3v4l.org/tglTAConstructor property promotion: https://3v4l.org/2hirZFoo|Baz
vsFoo | Baz
Throw as expression:$a = $b ?: throw Exception('b is falsy');
FILTER_VALIDATE_BOOL
overFILTER_VALIDATE_BOOLEAN
when usingfilter_var
PHP 8.1: https://www.php.net/manual/en/migration81.php
Array unpacking with string keys:$array = [...$otherData, 'b' => 1];
Named arguments used after argument unpacking:$result = foo(...$args, namedArg: 123)
https://3v4l.org/PN7kgfoo(...)
vsfoo( ... )
Foo&Bar
vsFoo & Bar
new
keyword in parameter initializers: https://3v4l.org/vcqT5PHP 8.2: https://github.com/php/php-src/milestone/4
Extra potential things to cover:
readonly
:public function __construct(readonly $foo)
The text was updated successfully, but these errors were encountered: