com php-src: Promote warnings to errors in wordwrap(): ext/standard/string.c ext/standard/tests/strings/wordwrap.phpt
ext/standard/tests/strings/wordwrap_error.phpt

From: Date: Thu, 22 Aug 2019 19:44:34 +0000
Subject: com php-src: Promote warnings to errors in wordwrap(): ext/standard/string.c ext/standard/tests/strings/wordwrap.phpt
ext/standard/tests/strings/wordwrap_error.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-107997@lists.php.net to get a copy of this message
Commit: 754d9f3da49c720d2945e6b2c95f652799681bf9 Author: George Peter Banyard <girgias@php.net> Thu, 22 Aug 2019 11:45:10 +0200 Parents: fe44e1637a683de9414e155f034bab993dd8aee3 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=754d9f3da49c720d2945e6b2c95f652799681bf9 Log: Promote warnings to errors in wordwrap() Changed paths: M ext/standard/string.c M ext/standard/tests/strings/wordwrap.phpt M ext/standard/tests/strings/wordwrap_error.phpt Diff: diff --git a/ext/standard/string.c b/ext/standard/string.c index ec43ddf..a1b6193 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 543c41f..8c2b08f 100644 --- a/ext/standard/tests/strings/wordwrap.phpt +++ b/ext/standard/tests/strings/wordwrap.phpt @@ -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 diff --git a/ext/standard/tests/strings/wordwrap_error.phpt b/ext/standard/tests/strings/wordwrap_error.phpt index ad75461..f0fa80f 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<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 --

« previous php.cvs (#107997) next »