Skip to content

re: Best Practice - Check if property exist and assign VIEW POST


why not do an foreach over the issues?
foreach($issue as $key=>$value){$i->{$key}=$value;}

sorry for missing spaces, but i am writing from my phone.

Also on if statement, even if there is one action, use the brackets!


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.



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.

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.



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.

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.

code of conduct - report abuse