Skip to content

Promote warnings to errors in wordwrap() #4597

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
10 changes: 5 additions & 5 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ PHP_FUNCTION(ltrim)
}
/* }}} */

/* {{{ proto string|false wordwrap(string str [, int width [, string break [, bool cut]]])
/* {{{ proto string wordwrap(string str [, int width [, string break [, bool cut]]])
Wraps buffer to selected number of characters using string break char */
PHP_FUNCTION(wordwrap)
{
Expand All @@ -933,13 +933,13 @@ PHP_FUNCTION(wordwrap)
}

if (breakchar_len == 0) {
php_error_docref(NULL, E_WARNING, "Break string cannot be empty");
RETURN_FALSE;
zend_throw_error(NULL, "Break string cannot be empty");
return;
}

if (linelength == 0 && docut) {
php_error_docref(NULL, E_WARNING, "Can't force cut when width is zero");
RETURN_FALSE;
zend_throw_error(NULL, "Can't force cut when width is zero");
return;
}

/* Special case for a single-character break as it needs no
Expand Down
11 changes: 9 additions & 2 deletions ext/standard/tests/strings/wordwrap.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ $tests = <<<TESTS

"123|==1234567890|==123" === wordwrap("123 1234567890 123", 10, "|==", 1)

FALSE === @wordwrap(chr(0), 0, "")

TESTS;

include(__DIR__ . '/../../../../tests/quicktester.inc');

echo "\n";

try {
wordwrap(chr(0), 0, "");
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
--EXPECT--
OK
Break string cannot be empty
11 changes: 7 additions & 4 deletions ext/standard/tests/strings/wordwrap_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ echo "-- width = 0 & cut = true --\n";
// width as zero and cut as true
$width = 0;
$cut = true;
var_dump( wordwrap($str, $width, $break, $cut) );

try {
wordwrap($str, $width, $break, $cut);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

echo "-- width = -10 & cut = false --\n";
// width as -ne and cut as false
Expand All @@ -49,9 +54,7 @@ echo "Done\n";
-- width = 0 & cut = false --
string(39) "testing<br />\nwordwrap<br />\nfunction"
-- width = 0 & cut = true --

Warning: wordwrap(): Can't force cut when width is zero in %s on line %d
bool(false)
Can't force cut when width is zero
-- width = -10 & cut = false --
string(39) "testing<br />\nwordwrap<br />\nfunction"
-- width = -10 & cut = true --
Expand Down