Skip to content

Unable to optional chain from parentheses #2447

Description

@cyreb7

@prettier/plugin-php v0.24.0
Playground link

Input:

<?php

($var)?->func();

Output:

Parse Error : syntax error, unexpected '?->' (T_NULLSAFE_OBJECT_OPERATOR), expecting ';' on line 3

  1 | <?php
  2 |
> 3 | ($var)?->func();
    |      ^

Prettier throws a syntax error when optional chaining from an expression wrapped in parentheses. Practical example that I was working on when I encountered this issue:

private function isSyncJob(object $job): bool
{
    return ($job->job ?? null)?->getConnectionName() === "sync";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions