In PHP 7, the following snippet weirdly prints true:
true
$b = true and false; var_dump($b);
However, if I drop it, it prints correctly false:
false
$b = (bool)(true and false); var_dump($b);
What phenomenon causes this?
This is not what it does, it is parentheses. andhas a lower priority than =, therefore your first statement is considered as
and
=
($b = true) and false;
You need to write:
$b = (true and false);
or
$b = true && false;
&&and andequivalent, with the exception of their priority (the same applies to ||and or).
&&
||
This is not casting, but parentheses:
$b = (true and false); var_dump($b); # => bool(false)
This is due to the fact that it binds more strongly than or . =andor
:
$b = true && false; var_dump($b); # => bool(false)
&& || , =.
Source: https://habr.com/ru/post/1660460/More articles:Removing brackets in R - regexGoogle login error: caused by: java.util.ConcurrentModificationException - androidHow to compile a 32-bit alpine greeting world? - cИспользование альфа-маски в TextView также удаляет родительский вид alpha? - androidWhat is the difference between optimizer.compute_gradient () and tf.gradients () in a tensor stream? - deep-learningGetting only sub in UserInfoEndpoint - openid-connectWhat is the difference between .post () ,. create () and perform_create () in views.py and .create () in serializers.py - pythonWSO2 - Management Registry - "Preliminary action must be completed" Failed to throw - wso2Remove random index from array List - javaКак добавить порядок в строку agg, когда два столбца объединены - postgresqlAll Articles