RE: [PHP] == vs = should generate a warning or error -- was: Why won't this work?

From: Date: Fri, 19 Jul 2002 23:36:42 +0000
Subject: RE: [PHP] == vs = should generate a warning or error -- was: Why won't this work?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-108601@lists.php.net to get a copy of this message
Plus, most programmer's editors allow regexp-based searches - and some even allow you to saved named patterns (eg; BBEdit, my fave). You could create a search to find all conditionals using a single = sign. It would have to be based on your particular style, but here's a wild, off-top-of-head, probably wrong/incomplete approach to finding things that look like while($row=mysql_fetch_row($result)) { : /while\s*([^=]+=[^=]+)\s*{/i I'm sure with a little thought that could also be extended to make sure parens were balanced and other neat stuff within the expression. -steve At 4:01 PM -0700 7/19/02, Rasmus Lerdorf wrote:
Wow, that should have been a quiz. I can't believe how many people
missed the == vs = thing and had all these elaborate answers. *grin* Which brings me to my point. Rasmus or any other PHP duder out there -- what are the possibilities of adding a config option in php.ini to WARN or ERROR when you try to use = instead of == in conditional checks like that.
That would suck since many many PHP programs use stuff like: while($row=mysql_fetch_row($result)) { ... } There is absolutely nothing wrong with doing an assignment in a conditional and if it generated a warning it would drive a lot of people crazy. -Rasmus
-- +------------------------------------------------------------------------+ | Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +------------------------------------------------------------------------+ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | +------------------------------------------------------------------------+

« previous php.general (#108601) next »