I've gotten bitten more than once by a bug where you accidentally assign a variable inside a conditional statement, like if
.
I'm looking to grep my sources for such occurances. I created an expression that works in PHP for the simple case, but was wondering if anyone could optimize it or handle the more interesting cases.
Samples:
if ($var = 3) //MATCH
if($var = 3) //MATCH
if($var=3) //MATCH
if ( $var = 3) //MATCH
if ($var == $var2)
if ($var = $var3) //MATCH
if ( $var === 7)
if( $var == 8 || $var = 9) //MATCH
if (($var == 7 ) && ($var ==10))
The simple cases are handled well by if\s*\([\$a-zA-Z\d\s]*=[\$a-zA-Z\d\s]*\)
but it would be nice to come up with something that works for the extended versions at the bottom of the sample.
Any ideas on better expressions?