summaryrefslogtreecommitdiff
path: root/Zend/tests/str_offset_004.phpt
blob: 02f00d581e7f071b9e2efefc64d7c1ad3450d1d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--TEST--
string offset 004
--FILE--
<?php
// Test assignments using (positive and negative) string offsets

$str = "abcdefghijklmno";
$i = 3;
$j = -4;

$str[2] = 'C';
var_dump($str);

$str[$i] = 'Z';
var_dump($str);

$str[-5] = 'P';
var_dump($str);

$str[$j] = 'Q';
var_dump($str);

$str[-20] = 'Y';
var_dump($str);

$str[-strlen($str)] = strtoupper($str[0]); /* An exotic ucfirst() ;) */
var_dump($str);

$str[20] = 'N';
var_dump($str);

$str[-2] = 'UFO';
var_dump($str);

$str[-$i] = $str[$j*2];
var_dump($str);
?>
--EXPECTF--
string(15) "abCdefghijklmno"
string(15) "abCZefghijklmno"
string(15) "abCZefghijPlmno"
string(15) "abCZefghijPQmno"

Warning: Illegal string offset -20 in %s on line %d
string(15) "abCZefghijPQmno"
string(15) "AbCZefghijPQmno"
string(21) "AbCZefghijPQmno     N"

Warning: Only the first byte will be assigned to the string offset in %s on line %d
string(21) "AbCZefghijPQmno    UN"
string(21) "AbCZefghijPQmno   nUN"