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

From: Date: Sat, 20 Jul 2002 01:33:15 +0000
Subject: RE: [PHP] == vs = should generate a warning or error -- was: Why won't this work?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-108608@lists.php.net to get a copy of this message
In article <003001c22f77$e640df20$67bb3f04@telecom>, daevid@daevid.com says... > Wow, that should have been a quiz. I can't believe how many people > missed the =3D=3D vs =3D 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 =3D instead of =3D=3D in conditional checks = > like > that. > > I can't tell you the number of minutes/hours wasted debugging code that > turned out to be that stupid mistake. While it's handy to use an > assignment in the conditional part, it can easily be done otherwise and > I for one would be glad to never use it to save me valuable time > tracking that down. Most other languages don't allow it. As others have pointed out, there are times when an assignment is valid in those circumstances. However, as a means of self protection :-) consider reversing your equivalence test, thus: if ("entrance" = $mode) { With suitable error reporting levels, that should spit a warning at you if you use assign instead of equivalence. (Not my original idea - picked it up from the mailing list ages ago) Cheers -- David Robley Temporary Kiwi! Quod subigo farinam

« previous php.general (#108608) next »