Which “if” construct is faster – statement or ternary operator?

There’s only one type of “if” statement there. The other is a conditional expression. As to which will perform better: they could compile to the same bytecode, and I would expect them to behave identically – or so close that you definitely wouldn’t want to choose one over the other in terms of performance. Sometimes … Read more

PHP shorthand for isset()? [duplicate]

Update for PHP 7 (thanks shock_gone_wild) PHP 7 introduces the null coalescing operator which simplifies the below statements to: $var = $var ?? “default”; Before PHP 7 No, there is no special operator or special syntax for this. However, you could use the ternary operator: $var = isset($var) ? $var : “default”; Or like this: … Read more

Omitting the second expression when using the if-else shorthand

What you have is a fairly unusual use of the ternary operator. Usually it is used as an expression, not a statement, inside of some other operation, e.g.: var y = (x == 2 ? “yes” : “no”); So, for readability (because what you are doing is unusual), and because it avoids the “else” that … Read more

CSS transition shorthand with multiple properties?

Syntax: transition: <property> || <duration> || <timing-function> || <delay> [, …]; Note that the duration must come before the delay, if the latter is specified. Individual transitions combined in shorthand declarations: -webkit-transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; -moz-transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; -o-transition: height 0.3s ease-out, opacity 0.3s ease 0.5s; … Read more

Multiline string literal in C#

You can use the @ symbol in front of a string to form a verbatim string literal: string query = @”SELECT foo, bar FROM table WHERE id = 42″; You also do not have to escape special characters when you use this method, except for double quotes as shown in Jon Skeet’s answer.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)