]> granicus.if.org Git - php/commitdiff
Promote warnings to errors in wordwrap()
authorGeorge Peter Banyard <girgias@php.net>
Thu, 22 Aug 2019 09:45:10 +0000 (11:45 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Thu, 22 Aug 2019 19:44:34 +0000 (21:44 +0200)
ext/standard/string.c
ext/standard/tests/strings/wordwrap.phpt
ext/standard/tests/strings/wordwrap_error.phpt

index ec43ddf70211f06355d0ce61b6a752864a972afd..a1b61933b3b5308bc4d06ad3ff641f195308778e 100644 (file)
@@ -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
index 543c41fdd97f6f1ec3dffddd90237d503568fe74..8c2b08f0462e7d19f6c6617b452d4e6d63d1a3d0 100644 (file)
@@ -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
index ad75461d3d19bd5feafd883d57f332e34a59eeb8..f0fa80f63d44079b1d00578603585a6af6d177ed 100644 (file)
@@ -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 --