note 88642 deleted from function.define by cmb
| From: | cmb@php.net | Date: | Sun, 06 Oct 2019 07:50:53 +0000 |
| Subject: | note 88642 deleted from function.define by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212472@lists.php.net to get a copy of this message | ||
Note Submitter: downwind at web dot de
----
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'";
}
?>