xref: /PHP-5.6/Zend/tests/offset_string.phpt (revision 896ac689)
1--TEST--
2using different variables to access string offsets
3--FILE--
4<?php
5
6$str = "Sitting on a corner all alone, staring from the bottom of his soul";
7
8var_dump($str[1]);
9var_dump($str[0.0836]);
10var_dump($str[NULL]);
11var_dump($str["run away"]);
12var_dump($str["13"]);
13var_dump($str["14.5"]);
14var_dump($str["15 and then some"]);
15
16var_dump($str[TRUE]);
17var_dump($str[FALSE]);
18
19$fp = fopen(__FILE__, "r");
20var_dump($str[$fp]);
21
22$obj = new stdClass;
23var_dump($str[$obj]);
24
25$arr = Array(1,2,3);
26var_dump($str[$arr]);
27
28echo "Done\n";
29?>
30--EXPECTF--
31string(1) "i"
32
33Notice: String offset cast occurred in %s on line %d
34string(1) "S"
35
36Notice: String offset cast occurred in %s on line %d
37string(1) "S"
38
39Warning: Illegal string offset 'run away' in %s on line %d
40string(1) "S"
41string(1) "c"
42
43Warning: Illegal string offset '14.5' in %s on line %d
44string(1) "o"
45
46Notice: A non well formed numeric value encountered in %s on line %d
47string(1) "r"
48
49Notice: String offset cast occurred in %s on line %d
50string(1) "i"
51
52Notice: String offset cast occurred in %s on line %d
53string(1) "S"
54
55Warning: Illegal offset type in %s on line %d
56string(1) "%s"
57
58Warning: Illegal offset type in %s on line %d
59
60Notice: Object of class stdClass could not be converted to int in %s on line %d
61string(1) "%s"
62
63Warning: Illegal offset type in %s on line %d
64string(1) "i"
65Done