Re: If statement being ignored by PHP

From: Date: Fri, 30 Jun 2000 05:56:54 +0000
Subject: Re: If statement being ignored by PHP
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-4061@lists.php.net to get a copy of this message
One of the habits drilled into me as a beginning C programmer was to put constants at the left of a test. e.g. if ("test" == post) { } so that if i make a mistake and do this : if ("test" = post) { } the compiler will scream bloody murder. ""Emile Axelrad"" <mail@protonic.com> wrote in message news:IPEHIDMPCBEOHFLIEOICGECGCDAA.mail@protonic.com... > > > if ($post="yes"): > > > > mail("$recipient <$remail>", "$sender has sent you a card", > > $message,"From: $semail \nReply-To: $semail\nX-Mailer: PHP3"); > > echo "Your card number $idnumber has been sent to $recipient."; > > endif; > > > > endif; > > > > PHP is a bastard - this is one problem which gets everyone at one point. > For if statements, the operator is == to check if it is equal to - not just > a single = sign. This is due to the fact that PHP will parse that statement > even in an if statement [i.e. set $post="yes", not work out whether it > equals yes.] > > Hope that helps - but if it doesn't make any sense just remember: > > if ($post=="yes") { > > blah; > > } > > NOT > > if ($post="yes") { > blah; > } > > Regards, > Emile Axelrad > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#4061) next »