Curly braces or colon-endif statements in PHP - which one provides better performance and code compatibility?

前端 未结 5 1747
耶瑟儿~
耶瑟儿~ 2021-01-07 22:03

I was looking through many snippets of code, and I have found that people can use the following two methods in an if statement:

Method 1:



        
5条回答
  •  清酒与你
    2021-01-07 22:36

    This alternative syntax is in no way different than the, perhaps, more familiar syntax. Just don't mix the two. Similar syntax exists for while, for, foreach, and switch.

    Typically you should choose your preferred syntax based upon readability, and your teams preference.

    What really might throw you is when you begin to see "if statements" which misuse logical conjunction operators like the following:

    isset( $value ) AND print( $value );
    

提交回复
热议问题