PHP basic traps (variable assignment ). Copy the code as follows :? Php $ a3; $ b6; if ($ a5 | $ b7) {$ a ++; $ B ++;} var_dump ($ a, $ B ); the $ a5 and $ b7 traps are regarded as $ a5 and $ b7. the error result is :.
The code is as follows:
$ A = 3;
$ B = 6;
If ($ a = 5 | $ B = 7 ){
$ A ++;
$ B ++;
}
Var_dump ($ a, $ B );
Trap 1
Consider $ a = 5 and $ B = 7 as $ a = 5 and $ B = 7.
Error result: 3, 6
Trap 2
Operator priority. $ a = 5 is assigned successfully. $ B = 7 is not executed.
Error result: 6, 7
Correct understanding
The trap is the priority of the operator, and the priority of the value assignment operator (=) is the lowest, so the correct understanding should be
$ A = (5 | $ B = 7)
Correct results: true, 7
Upgrade
Deformation 1
The code is as follows:
$ A = 3;
$ B = 6;
$ C = 1;
If ($ a = 5 | $ B = 7 & $ c = 10 ){
$ A ++;
$ B ++;
}
Var_dump ($ a, $ B, $ c );
Deformation 2
The code is as follows:
$ A = 3;
$ B = 6;
$ C = 1;
If ($ a = 0 | $ B = 7 & $ c = 10 ){
$ A ++;
$ B ++;
}
Var_dump ($ a, $ B, $ c );
If you are interested, you can think about it :)
The http://www.bkjia.com/PHPjc/326013.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326013.htmlTechArticle code is as follows :? Php $ a = 3; $ B = 6; if ($ a = 5 | $ B = 7) {$ a ++; $ B ++ ;} var_dump ($ a, $ B); Trap 1 regards $ a = 5 and $ B = 7 as error results of $ a = 5 and $ B = 7: 3, 6 trap operator optimization...