summaryrefslogtreecommitdiff
path: root/Zend/tests/exception_from_toString.phpt
blob: ee6dde9187c3378e140e05c204a79127e18782eb (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
--TEST--
Test exceptions thrown from __toString() in various contexts
--FILE--
<?php

class BadStr {
    public function __toString() {
        throw new Exception("Exception");
    }
}

$str = "a";
$num = 42;
$badStr = new BadStr;

try { $x = $str . $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = $badStr . $str; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = $str .= $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump($str); 
try { $x = $num . $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = $badStr . $num; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = $num .= $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump($num);

try { $x = $badStr .= $str; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump($badStr);
try { $x = $badStr .= $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump($badStr);

try { $x = "x$badStr"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = "{$badStr}x"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = "$str$badStr"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = "$badStr$str"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

try { $x = "x$badStr$str"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = "x$str$badStr"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = "{$str}x$badStr"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
try { $x = "{$badStr}x$str"; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

try { $x = (string) $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

try { $x = include $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

try { echo $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

${""} = 42;
try { unset(${$badStr}); }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump(${""});

unset(${""});
try { $x = ${$badStr}; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

try { $x = isset(${$badStr}); }
catch (Exception $e) { echo $e->getMessage(), "\n"; }

$obj = new stdClass;
try { $x = $obj->{$badStr} = $str; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump($obj);

try { $str[0] = $badStr; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump($str);

$obj = new DateInterval('P1D');
try { $x = $obj->{$badStr} = $str; }
catch (Exception $e) { echo $e->getMessage(), "\n"; }
var_dump(!isset($obj->{""}));

try { strlen($badStr); } catch (Exception $e) { echo "Exception\n"; }
try { substr($badStr, 0); } catch (Exception $e) { echo "Exception\n"; }
try { new ArrayObject([], 0, $badStr); } catch (Exception $e) { echo "Exception\n"; }

?>
--EXPECT--
Exception
Exception
Exception
string(1) "a"
Exception
Exception
Exception
int(42)
Exception
object(BadStr)#1 (0) {
}
Exception
object(BadStr)#1 (0) {
}
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
int(42)
Exception
Exception
Exception
object(stdClass)#2 (0) {
}
Exception
string(1) "a"
Exception
bool(true)
Exception
Exception
Exception