xref: /PHP-8.2/Zend/tests/str_offset_004.phpt (revision d30cd7d7)
1--TEST--
2string offset 004
3--FILE--
4<?php
5// Test assignments using (positive and negative) string offsets
6
7$str = "abcdefghijklmno";
8$i = 3;
9$j = -4;
10
11$str[2] = 'C';
12var_dump($str);
13
14$str[$i] = 'Z';
15var_dump($str);
16
17$str[-5] = 'P';
18var_dump($str);
19
20$str[$j] = 'Q';
21var_dump($str);
22
23$str[-20] = 'Y';
24var_dump($str);
25
26$str[-strlen($str)] = strtoupper($str[0]); /* An exotic ucfirst() ;) */
27var_dump($str);
28
29$str[20] = 'N';
30var_dump($str);
31
32$str[-2] = 'UFO';
33var_dump($str);
34
35$str[-$i] = $str[$j*2];
36var_dump($str);
37?>
38--EXPECTF--
39string(15) "abCdefghijklmno"
40string(15) "abCZefghijklmno"
41string(15) "abCZefghijPlmno"
42string(15) "abCZefghijPQmno"
43
44Warning: Illegal string offset -20 in %s on line %d
45string(15) "abCZefghijPQmno"
46string(15) "AbCZefghijPQmno"
47string(21) "AbCZefghijPQmno     N"
48
49Warning: Only the first byte will be assigned to the string offset in %s on line %d
50string(21) "AbCZefghijPQmno    UN"
51string(21) "AbCZefghijPQmno   nUN"
52