Given:
if ($variable = get_variable('variable')) {
// ...
}
The *$variable = get_variable('variable')* throws an 'Assignment in condition' warning in Zend Studio. I understand what the warning means, but does anyone know what the rationale behind it is? Is it merely coding conventions, a matter of readability, etc.?
This is a very common warning issued by IDEs/compilers in most languages that allow this construct: since =
(assignment) and ==
(comparison) are very similar, and comparison is more common within an if
statement, the warning is just there to let you know that you may have put in an assignment by mistake where you really intended a comparison.