This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 228521 - Ternary operator inconsistent Formatting
Summary: Ternary operator inconsistent Formatting
Status: RESOLVED INCOMPLETE
Alias: None
Product: php
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 7.4
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
: 238449 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-04-12 15:22 UTC by berniev
Modified: 2016-06-10 11:28 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description berniev 2013-04-12 15:22:01 UTC
Dev Build 201304102301

Menu->Options->Editor->Formatting->php->Wrapping->Ternary=Always

<?php
/* WITH middle part */
$b = $a
    ? $b
    : $c; // As expected. ? Always forced to second line

$b = $a
    ?
    $b
    :
    $c; // Not on same line as operators not moved. Bug? IMHO yes.

$b = $a
    ? $b
    :
    $c; // Testing just second part. Ditto above.

    $b = $a
    ?
    $b
    : $c; // Testing just second part. Ditto above.

/* WITHOUT middle part */
$b = $a
    ?
    : $c; // kind of expected ... 

/*
 * or should it be ..
 * $b = $a
 *      ? : $c // Personally I prefer this but then what do I know?!
 *
 */

$b = $a ?
    : $c; // The ? is left on the first line, unlike with middle part

$b = $a?
    : $c; // ? not spaced

$b = $a?
    : 
    $c; // Combining 
?>
Comment 1 Ondrej Brejla 2013-12-03 10:03:43 UTC
*** Bug 238449 has been marked as a duplicate of this bug. ***
Comment 2 Ondrej Brejla 2013-12-03 10:04:29 UTC
Case from duplicate issue #238449

When you omit the value between the ? and : of the ternary operator, formatting the code should combine them into a single operator without any space between.

    $color = $color ?: "blue";    // combine, good

rather than

    $color = $color ? : "blue";   // split, bad
Comment 3 berniev 2013-12-03 11:33:52 UTC
My 2c...

If Wrapping->Ternary is set to always then cannot agree, as 'always' is absolute.
The idea has merit, but to make sense there would have to be an additional options setting eg always unless no space ?? Or something.
Comment 4 Tomas Mysik 2016-06-10 11:28:34 UTC
There were some changes in this area in the current release - could you please try the dev version of NetBeans [1]? Simply reopen this issue and let us know.

Thanks.
[1] http://bits.netbeans.org/download/trunk/nightly/latest/