note 98673 added to function.strpos
| From: | hysterix at hysterix dot null | Date: | Tue, 29 Jun 2010 22:25:41 +0000 |
| Subject: | note 98673 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170572@lists.php.net to get a copy of this message | ||
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 />';
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 75.4.249.49
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/98673
Del: integrated -- https://master.php.net/note/delete/98673/integrated
Del: useless -- https://master.php.net/note/delete/98673/useless
Del: bad code -- https://master.php.net/note/delete/98673/bad+code
Del: spam -- https://master.php.net/note/delete/98673/spam
Del: non-english -- https://master.php.net/note/delete/98673/non-english
Del: in docs -- https://master.php.net/note/delete/98673/in+docs
Del: other reasons-- https://master.php.net/note/delete/98673
Reject -- https://master.php.net/note/reject/98673
Search -- https://master.php.net/manage/user-notes.php