Bug #15691 Updated: Returns from strpos()

From: Date: Sun, 24 Feb 2002 15:23:35 +0000
Subject: Bug #15691 Updated: Returns from strpos()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-952@lists.php.net to get a copy of this message
ID: 15691 Updated by: rasmus@php.net Reported By: mjohnwood@hotmail.com Status: Closed Bug Type: Feature/Change Request Operating System: Any PHP Version: 4.1.1 New Comment: I think returning -1 would be much worse. That would mean that if(strpos($str,"foo")) would evaluate to true when "foo" does not exist in $str. Bad idea. What has been suggested is to have it start at 1 instead of 0 to indicate a match in the first position. That is a better idea, except it is inconsistent with the rest of PHP. String indices start at 0 and often the result of a strpos() is passed to substr() in which case starting the strpos() return at 1 would really confuse people. The way it currently is implemented is the most consistent and least confusing in my opinion. Previous Comments: ------------------------------------------------------------------------ [2002-02-23 15:23:02] derick@php.net Changing this behavior will break way too many scripts, so it's absolutely not a good idea to change this behavior. Derick ------------------------------------------------------------------------ [2002-02-23 15:12:51] mjohnwood@hotmail.com It would be boundlessly helpful if someone could make strpos(), etc. return a -1 instead of FALSE like C++/Java. Returning a FALSE (something that casts to an integer of 0) doesn't seem to make much sense. Even if it can be worked around with strpos() === FALSE, it would be a lot easier without having to rely upon it. Any reason why it should be using FALSE instead of -1? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15691&edit=1

« previous php.bugs (#952) next »