0

first of all, I am quite new to PHP and web development in general. I see people using the Ternary Operators quite a lot but sometimes I like the following solution. If there is only need for if statements, is the following code against any general php convention ?

if($result->num_rows < 1) return $response->error(400, "Target with ID " . $target->id . " does not exist");

Best regards, Fabian

1
  • 2
    That's a very opinionated question. About conventions you might check php-fig.org (PHP Standard Recommendation) Commented Apr 29, 2020 at 0:33

1 Answer 1

1

Although the PSR-12 doesn't allow the use of if statements without braces, it's a widely used practice in the community, especially to do quick early returns.

Sign up to request clarification or add additional context in comments.

1 Comment

Quick early returns is exactly what I need. Wrapping braces around it in the same line sounds quite silly so I guess I´ll go with the community and use it. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.