|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-01-10 19:06 UTC] 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"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 21:00:01 2025 UTC |
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;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>).