DEV Community

Discussion on: Best Practice - Check if property exist and assign

Collapse
 
mlueckl profile image
Michael Lueckl

That's awesome! I wasn't aware you can set the property name like this which makes my case so much easier :D

Can you please elaborate on why if statement should always use brackets?
So far I did not run into problems here but would like to understand your reason for saying this.

Cheers

Collapse
 
alexcioroianu profile image
Alex Cioroianu

i always use brackets because it is easyer to read and extend.

for example, if you want to add another action inside the if statement, you need to add the brackets anyway.

it’s a best practice that will help you and the developes after you to better understand the logic.

Thread Thread
 
mlueckl profile image
Michael Lueckl

I did indeed run into the case that I added another statement and missed the brackets :)
But overall I agree, was thinking there is a specific technical reason.

Thanks!

Collapse
 
belinde profile image
Franco Traversaro

Consider following PSR-1 and PSR-2 coding standards. PSR are recommendations of the php-fig group, they're becoming a de facto standard. The more developers follow a single style standard, the easier become understand someone else code.

Thread Thread
 
mlueckl profile image
Michael Lueckl

This is great and I will look into this.
I always try to adjust my style to a standard because I strongly agree that standards are very useful.