From 1e76f5e6846dc434e97e7be40f7ccabe9ac1e59f Mon Sep 17 00:00:00 2001 From: Jesus Valera Reales Date: Mon, 12 Aug 2024 15:50:44 +0200 Subject: [PATCH 1/3] Add ternary operator on multi-line --- spec.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec.md b/spec.md index 67ee55a..8e360a3 100644 --- a/spec.md +++ b/spec.md @@ -1057,6 +1057,10 @@ and `:` characters: ```php $variable = $foo ? 'foo' : 'bar'; + +$variableMultiLine = $foo + ? 'foo' + : 'bar'; ``` When the middle operand of the conditional operator is omitted, the operator From 145af4e442d3d1cb4cdd6e151321ed2487beb0aa Mon Sep 17 00:00:00 2001 From: JesusValera Date: Thu, 3 Oct 2024 17:48:45 +0200 Subject: [PATCH 2/3] Create "Operators placement" section --- spec.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/spec.md b/spec.md index 8e360a3..559bc31 100644 --- a/spec.md +++ b/spec.md @@ -1057,10 +1057,6 @@ and `:` characters: ```php $variable = $foo ? 'foo' : 'bar'; - -$variableMultiLine = $foo - ? 'foo' - : 'bar'; ``` When the middle operand of the conditional operator is omitted, the operator @@ -1070,6 +1066,25 @@ MUST follow the same style rules as other binary [comparison][] operators: $variable = $foo ?: 'bar'; ``` +### 6.4. Operator's placement + +When a statement that includes an operator must be split into multiple lines, +the operator SHOULD be placed at the beginning of the new line. + +```php + Date: Sun, 6 Oct 2024 18:22:10 +0200 Subject: [PATCH 3/3] Apply suggestions to "Operators placement" section --- spec.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec.md b/spec.md index 559bc31..e2604b9 100644 --- a/spec.md +++ b/spec.md @@ -1068,19 +1068,22 @@ $variable = $foo ?: 'bar'; ### 6.4. Operator's placement -When a statement that includes an operator must be split into multiple lines, -the operator SHOULD be placed at the beginning of the new line. +A statement that includes an operator MAY be split across multiple lines, where +each subsequent line is indented once. When doing so, the operator MUST be +placed at the beginning of the new line; ternaries MUST occupy 3 lines, never 2. + +For example: ```php