Req #43809 [Opn->Csd]: strtok() should return FALSE if needle wasnt found

From: Date: Thu, 21 Sep 2017 16:09:07 +0000
Subject: Req #43809 [Opn->Csd]: strtok() should return FALSE if needle wasnt found
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211313@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=43809&edit=1

 ID:                 43809
 Updated by:         cmb@php.net
 Reported by:        admin at ifyouwantblood dot de
 Summary:            strtok() should return FALSE if needle wasnt found
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
 Package:            Strings related
 Operating System:   Any
 PHP Version:        5.2.5
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Besides that PHP's strtok() basically follows the POSIX specification, changing
the behavior as suggested would make the result ambiguous, because

    strtok('something', ':')

and

    strtok('', ':')

and

    strtok(':::', ':')

would all return FALSE, and it wouldn't be easy to distinguish these cases.

I don't think changing the behavior would be a good idea. If you think otherwise
please feel free to start the RFC process (<https://wiki.php.net/rfc/howto>).


Previous Comments:
------------------------------------------------------------------------
[2008-01-11 00:09:44] felipe@php.net

Looks fine to me. My try:

Index: string.c
===================================================================
RCS file: /repository/php-src/ext/standard/string.c,v
retrieving revision 1.445.2.14.2.69.2.8
diff -u -r1.445.2.14.2.69.2.8 string.c
--- string.c    31 Dec 2007 07:17:15 -0000      1.445.2.14.2.69.2.8
+++ string.c    11 Jan 2008 00:00:34 -0000
@@ -1264,7 +1264,7 @@
                }
        }
 
-       if (p - BG(strtok_last)) {
+       if ((skipped || BG(strtok_len) != strlen(BG(strtok_last))) && p - BG(strtok_last)) {
 return_token:
                RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped, 1);
                BG(strtok_last) = p + 1;


------------------------------------------------------------------------
[2008-01-10 19:06:45] admin at ifyouwantblood dot de

Description:
------------
In PHP 4.1 strtok() has been changed to return FALSE if a repeated token wasnt found in the haystack
string. It should also return FALSE if needle wasnt found at first place.

Reproduce code:
---------------
<?php

$something=strtok('something',':');
var_dump($something);

?>

Expected result:
----------------
bool(false)

Actual result:
--------------
string(9) "something"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=43809&edit=1


Thread (3 messages)

« previous php.bugs (#211313) next »