note 98673 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Tue, 29 Jun 2010 22:29:28 +0000 |
| Subject: | note 98673 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170573@lists.php.net to get a copy of this message | ||
Note Submitter: hysterix at hysterix dot null
----
Even with error_reporting(E_ALL), the following generates confusing logic errors, but no syntax
errors.
Is this a bug in php? I don't know, but this can't be correct!
Hope this saves someone else some headaches!
<?php
$str1 = 'hai';
$str2 = 'what is this, i dont even! so anyways i says to mabel i says....';
echo 'String 1 is: '.$str1.'<br />';
echo 'String 2 is: '.$str2.'<br /><br />';
echo 'incorrect behavior<br />';
if(strpos($str1,$str2 === false)) { // this wont work, yet no syntax errors are fired off
// this will never work
echo 'string not found!<br />';
} else {
// this will instead fire every time even if the string is not in there
echo 'string found!<br />';
}
echo '<br />';
echo 'correct behavior<br />';
if(strpos($str1,$str2) === false) {
// this will actually fire off
echo 'string not found!<br />';
} else {
echo 'string found!<br />';
}
?>