---
title: "What is the preferred way to write this if statement, and why?"  
description: "What is the preferred way to write this if statement, and why?"  
author: "Erick Wilsom"  
published: 2022-10-27  
updated: 2022-10-27  
canonical: https://www.mindstick.com/forum/157176/what-is-the-preferred-way-to-write-this-if-statement-and-why  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# What is the preferred way to write this if statement, and why?

What is the preferred way to write this [if statement](https://www.mindstick.com/forum/12682/jquery-toggle-if-statement), and why?

```
if( 5 == $someVar ) or if( $someVar == 5 )
```

\

## Replies

### Reply by Kirti Sharma

The **if( $someVar == 5 )** is the preferred way to assign condition under the if situation.

### Reply by Siddhi Malviya

The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2 equalsigns($someVar = 5), and will cause an error, the latter won't.


---

Original Source: https://www.mindstick.com/forum/157176/what-is-the-preferred-way-to-write-this-if-statement-and-why

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
