-1

code1 is a code from zencart core php file, I am confused what it is.
is code1 equal to code2 ?
and what is the & ~ meanning ?

<?php 
/* code1 */
$errors_to_log = (version_compare(PHP_VERSION, 5.3, '>=') ? E_ALL & ~E_DEPRECATED & ~E_NOTICE : version_compare(PHP_VERSION, 5.4, '>=') ? E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT : E_ALL & ~E_NOTICE);

/* code2 */
if(version_compare(PHP_VERSION,5.3,'>=')){
    $errors_to_log = E_ALL & ~E_DEPRECATED &~E_NOTICE;
}else if(version_compare(PHP_VERSION, 5.4, '>=')){
    $errors_to_log = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT;
}else{
    $errors_to_log = E_ALL & ~E_NOTICE;
}
?>
mingfish_004
  • 1,223
  • 2
  • 16
  • 26
  • usually in php, `&` refers to `BITWISE AND` operator and `~` refers to `BITWISE NOT` operator (bit inversion)... – Kevin Jun 11 '13 at 02:15
  • 4
    [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – mario Jun 11 '13 at 02:16

1 Answers1

1

Is code 1 equal to code 2?

Yes. Code 1 uses nested ternary operator while code 2 uses the else-if structure. Code 1 would've been more clear if parentheses were used to show the precedence.

What do & and ~ mean?

& in php refers to BITWISE AND operator. ~ in php refers to BITWISE NOT or Complement operator. In this case, it gives the complement values of the constants.

However, you need to know that ~ has the highest precedence here.

Kevin
  • 5,891
  • 5
  • 36
  • 52