]> granicus.if.org Git - php/commitdiff
Promote warnings to errors in str_repeat()
authorGeorge Peter Banyard <girgias@php.net>
Thu, 22 Aug 2019 09:28:22 +0000 (11:28 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Fri, 23 Aug 2019 18:01:19 +0000 (20:01 +0200)
ext/mbstring/tests/bug73646.phpt
ext/opcache/tests/bug70207.phpt
ext/standard/string.c
ext/standard/tests/strings/str_repeat.phpt
ext/standard/tests/strings/str_repeat_variation1.phpt [new file with mode: 0644]

index 7ac824d69cb4d6d129cbd75af61a1296bf0473fa..ea57017f1167c4511b843f766e7192d03ab918b7 100644 (file)
@@ -7,10 +7,7 @@ if (!function_exists('mb_ereg')) die('skip mbregex support not available');
 ?>
 --FILE--
 <?php
-
-$v1=str_repeat("#", -1);
-var_dump(mb_ereg_search_init($v1));
+var_dump(mb_ereg_search_init(NULL));
 ?>
---EXPECTF--
-Warning: str_repeat(): Second argument has to be greater than or equal to 0 in %sbug73646.php on line %d
+--EXPECT--
 bool(true)
index 806ea7535b67e1410915fa59abfbae467c1425be..2b6e48a2d4b23ec1b702c1381da6d9fb288cce1e 100644 (file)
@@ -14,7 +14,9 @@ function bar() {
 }
 function foo() {
     try { return bar(); }
-    finally { @str_repeat("foo", -10); }
+    finally {
+        @fopen("non-existent", 'r');
+    }
 }
 
 var_dump(foo());
index 97114e88b65b8af90451779ff36fe48464d7083e..8b97d0797dfd47ead77cf099c20e852d6d1b2011 100644 (file)
@@ -5363,7 +5363,7 @@ PHP_FUNCTION(str_repeat)
        ZEND_PARSE_PARAMETERS_END();
 
        if (mult < 0) {
-               php_error_docref(NULL, E_WARNING, "Second argument has to be greater than or equal to 0");
+               zend_throw_error(NULL, "Second argument has to be greater than or equal to 0");
                return;
        }
 
index 766bea1f9c32df17825d32ffe184a7be19a54dbd..6e5f0cf68e618ec40a8e0db1fabfba3406d77b3f 100644 (file)
Binary files a/ext/standard/tests/strings/str_repeat.phpt and b/ext/standard/tests/strings/str_repeat.phpt differ
diff --git a/ext/standard/tests/strings/str_repeat_variation1.phpt b/ext/standard/tests/strings/str_repeat_variation1.phpt
new file mode 100644 (file)
index 0000000..4740f7c
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Test str_repeat() function: usage variations - complex strings containing other than 7-bit chars
+--INI--
+precision=14
+--FILE--
+<?php
+$str = chr(0).chr(128).chr(129).chr(234).chr(235).chr(254).chr(255);
+
+$withCodePoint = str_repeat($str, chr(51)); // ASCII value of '3' given
+$explicit = str_repeat($str, 3);
+
+var_dump($withCodePoint === $explicit);
+var_dump( bin2hex( $withCodePoint ) );
+var_dump( bin2hex( $explicit ) );
+
+?>
+DONE
+--EXPECT--
+bool(true)
+string(42) "008081eaebfeff008081eaebfeff008081eaebfeff"
+string(42) "008081eaebfeff008081eaebfeff008081eaebfeff"
+DONE