note 88642 added to function.define

From: Date: Mon, 02 Feb 2009 04:48:25 +0000
Subject: note 88642 added to function.define
Groups: php.notes 
Request: Send a blank email to php-notes+get-150086@lists.php.net to get a copy of this message
I'm reffering to the note below by mittiprovence. The described behavior has nothing to do with the fact that there is a constant in the condition. Comparing a non-numeric string to the integer 0 by using == will return true, since the string will be casted to integer - which will be zero. If your string starts with a number, it will be castet to an integer with the number as value. To avoid the described behavior, you should use === instead of ==. Finally, the behavior discribed by mittiprovence is exacly the expected behavior as defined in the manual. For further information read the manual: http://www.php.net/manual/en/types.comparisons.php http://www.php.net/manual/en/language.operators.comparison.php http://www.php.net/manual/en/language.types.string.php #language.types.string.conversion <?php if (0 == "some string") { // is true echo "0 == 'some string'"; } if (1 == "some string") { // is false echo "1 == 'some string'"; } if (1 == "1 some string") { // is true echo "1 == '1 some string'"; } if (0 === "some string") { // is false echo "0 === 'some string'"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.170.75.136 ---- Manual Page -- http://www.php.net/manual/en/function.define.php Edit -- https://master.php.net/note/edit/88642 Del: integrated -- https://master.php.net/note/delete/88642/integrated Del: useless -- https://master.php.net/note/delete/88642/useless Del: bad code -- https://master.php.net/note/delete/88642/bad+code Del: spam -- https://master.php.net/note/delete/88642/spam Del: non-english -- https://master.php.net/note/delete/88642/non-english Del: in docs -- https://master.php.net/note/delete/88642/in+docs Del: other reasons-- https://master.php.net/note/delete/88642 Reject -- https://master.php.net/note/reject/88642 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150086) next »