Skip to content

Commit 754d9f3

Browse files
committed
Promote warnings to errors in wordwrap()
1 parent fe44e16 commit 754d9f3

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

ext/standard/string.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ PHP_FUNCTION(ltrim)
907907
}
908908
/* }}} */
909909

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

935935
if (breakchar_len == 0) {
936-
php_error_docref(NULL, E_WARNING, "Break string cannot be empty");
937-
RETURN_FALSE;
936+
zend_throw_error(NULL, "Break string cannot be empty");
937+
return;
938938
}
939939

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

945945
/* Special case for a single-character break as it needs no

ext/standard/tests/strings/wordwrap.phpt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ $tests = <<<TESTS
2727
2828
"123|==1234567890|==123" === wordwrap("123 1234567890 123", 10, "|==", 1)
2929
30-
FALSE === @wordwrap(chr(0), 0, "")
31-
3230
TESTS;
3331

3432
include(__DIR__ . '/../../../../tests/quicktester.inc');
33+
34+
echo "\n";
35+
36+
try {
37+
wordwrap(chr(0), 0, "");
38+
} catch (\Error $e) {
39+
echo $e->getMessage() . "\n";
40+
}
3541
--EXPECT--
3642
OK
43+
Break string cannot be empty

ext/standard/tests/strings/wordwrap_error.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ echo "-- width = 0 & cut = true --\n";
2626
// width as zero and cut as true
2727
$width = 0;
2828
$cut = true;
29-
var_dump( wordwrap($str, $width, $break, $cut) );
29+
30+
try {
31+
wordwrap($str, $width, $break, $cut);
32+
} catch (\Error $e) {
33+
echo $e->getMessage() . "\n";
34+
}
3035

3136
echo "-- width = -10 & cut = false --\n";
3237
// width as -ne and cut as false
@@ -49,9 +54,7 @@ echo "Done\n";
4954
-- width = 0 & cut = false --
5055
string(39) "testing<br />\nwordwrap<br />\nfunction"
5156
-- width = 0 & cut = true --
52-
53-
Warning: wordwrap(): Can't force cut when width is zero in %s on line %d
54-
bool(false)
57+
Can't force cut when width is zero
5558
-- width = -10 & cut = false --
5659
string(39) "testing<br />\nwordwrap<br />\nfunction"
5760
-- width = -10 & cut = true --

0 commit comments

Comments
 (0)