diff --git a/ext/standard/string.c b/ext/standard/string.c index c2f29baec7732..7e2c5729de2d1 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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) { @@ -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 diff --git a/ext/standard/tests/strings/wordwrap.phpt b/ext/standard/tests/strings/wordwrap.phpt index 543c41fdd97f6..8c2b08f0462e7 100644 --- a/ext/standard/tests/strings/wordwrap.phpt +++ b/ext/standard/tests/strings/wordwrap.phpt @@ -27,10 +27,17 @@ $tests = <<getMessage() . "\n"; +} --EXPECT-- OK +Break string cannot be empty diff --git a/ext/standard/tests/strings/wordwrap_error.phpt b/ext/standard/tests/strings/wordwrap_error.phpt index ad75461d3d19b..f0fa80f63d440 100644 --- a/ext/standard/tests/strings/wordwrap_error.phpt +++ b/ext/standard/tests/strings/wordwrap_error.phpt @@ -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 @@ -49,9 +54,7 @@ echo "Done\n"; -- width = 0 & cut = false -- string(39) "testing
\nwordwrap
\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
\nwordwrap
\nfunction" -- width = -10 & cut = true --