xref: /PHP-8.0/Zend/tests/bug71572.phpt (revision bfe3f934)
1--TEST--
2Bug #71572: String offset assignment from an empty string inserts null byte
3--FILE--
4<?php
5
6$str = "abc";
7try {
8    var_dump($str[0] = "");
9} catch (\Error $e) {
10    echo $e->getMessage() . \PHP_EOL;
11}
12try {
13    var_dump($str[1] = "");
14} catch (\Error $e) {
15    echo $e->getMessage() . \PHP_EOL;
16}
17try {
18    var_dump($str[3] = "");
19} catch (\Error $e) {
20    echo $e->getMessage() . \PHP_EOL;
21}
22try {
23    var_dump($str[10] = "");
24} catch (\Error $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27var_dump($str);
28?>
29--EXPECT--
30Cannot assign an empty string to a string offset
31Cannot assign an empty string to a string offset
32Cannot assign an empty string to a string offset
33Cannot assign an empty string to a string offset
34string(3) "abc"
35