Skip to content

Promote warnings to errors in strpbrk() #4598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -6068,8 +6068,8 @@ PHP_FUNCTION(strpbrk)
ZEND_PARSE_PARAMETERS_END();

if (!ZSTR_LEN(char_list)) {
php_error_docref(NULL, E_WARNING, "The character list cannot be empty");
RETURN_FALSE;
zend_value_error("The character list cannot be empty");
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative here would be to drop the warning instead and return false -- this is consistent with searching for an empty list of characters, which will never be found.

Not sure whether that's actually a good idea though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion in this, maybe let internals decide?

}

for (haystack_ptr = ZSTR_VAL(haystack); haystack_ptr < (ZSTR_VAL(haystack) + ZSTR_LEN(haystack)); ++haystack_ptr) {
Expand Down
18 changes: 8 additions & 10 deletions ext/standard/tests/strings/strpbrk_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ Test strpbrk() function : error conditions
* Alias to functions:
*/

echo "*** Testing strpbrk() : error conditions ***\n";

$haystack = 'This is a Simple text.';

echo "\n-- Testing strpbrk() function with empty second argument --\n";
var_dump( strpbrk($haystack, '') );
echo "-- Testing strpbrk() function with empty second argument --\n";
try {
strpbrk($haystack, '');
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

?>
--EXPECTF--
*** Testing strpbrk() : error conditions ***

--EXPECT--
-- Testing strpbrk() function with empty second argument --

Warning: strpbrk(): The character list cannot be empty in %s on line %d
bool(false)
The character list cannot be empty