xref: /PHP-8.4/Zend/tests/gc_038.phpt (revision 902d6439)
1--TEST--
2GC 038: Garbage created by compound assignment operators (e.g. +=)
3--INI--
4zend.enable_gc = 1
5--FILE--
6<?php
7function test_add() {
8    $x = new stdClass;
9    $x->x = $x;
10    try {
11        $x += 5;
12    } catch (TypeError $e) { unset($x); }
13    $n = gc_collect_cycles();
14    echo "+=\t$n\n";
15}
16test_add();
17
18function test_sub() {
19    $x = new stdClass;
20    $x->x = $x;
21    try {
22        $x -= 5;
23    } catch (TypeError $e) { unset($x); }
24    $n = gc_collect_cycles();
25    echo "-=\t$n\n";
26}
27test_sub();
28
29function test_mul() {
30    $x = new stdClass;
31    $x->x = $x;
32    try {
33        $x *= 5;
34    } catch (TypeError $e) { unset($x); }
35    $n = gc_collect_cycles();
36    echo "*=\t$n\n";
37}
38test_mul();
39
40function test_div() {
41    $x = new stdClass;
42    $x->x = $x;
43    try {
44        $x /= 5;
45    } catch (TypeError $e) { unset($x); }
46    $n = gc_collect_cycles();
47    echo "/=\t$n\n";
48}
49test_div();
50
51function test_mod() {
52    $x = new stdClass;
53    $x->x = $x;
54    try {
55        $x %= 5;
56    } catch (TypeError $e) { unset($x); }
57    $n = gc_collect_cycles();
58    echo "%=\t$n\n";
59}
60test_mod();
61
62function test_sl() {
63    $x = new stdClass;
64    $x->x = $x;
65    try {
66        $x <<= 5;
67    } catch (TypeError $e) { unset($x); }
68    $n = gc_collect_cycles();
69    echo "<<=\t$n\n";
70}
71test_sl();
72
73function test_sr() {
74    $x = new stdClass;
75    $x->x = $x;
76    try {
77        $x >>= 5;
78    } catch (TypeError $e) { unset($x); }
79    $n = gc_collect_cycles();
80    echo ">>=\t$n\n";
81}
82test_sr();
83
84function test_or() {
85    $x = new stdClass;
86    $x->x = $x;
87    try {
88        $x |= 5;
89    } catch (TypeError $e) { unset($x); }
90    $n = gc_collect_cycles();
91    echo "|=\t$n\n";
92}
93test_or();
94
95function test_and() {
96    $x = new stdClass;
97    $x->x = $x;
98    try {
99        $x &= 5;
100    } catch (TypeError $e) { unset($x); }
101    $n = gc_collect_cycles();
102    echo "&=\t$n\n";
103}
104test_and();
105
106function test_xor() {
107    $x = new stdClass;
108    $x->x = $x;
109    try {
110        $x ^= 5;
111    } catch (TypeError $e) { unset($x); }
112    $n = gc_collect_cycles();
113    echo "^=\t$n\n";
114}
115test_xor();
116
117function test_pow() {
118    $x = new stdClass;
119    $x->x = $x;
120    try {
121        $x **= 5;
122    } catch (TypeError $e) { unset($x); }
123    $n = gc_collect_cycles();
124    echo "**=\t$n\n";
125}
126test_pow();
127
128class Y {
129    public $x;
130    function __toString() {
131        return "y";
132    }
133}
134function test_concat() {
135    $x = new Y;
136    $x->x = $x;
137    @$x .= "x";
138    $n = gc_collect_cycles();
139    echo ".=\t$n\n";
140}
141test_concat();
142?>
143--EXPECTF--
144+=	1
145-=	1
146*=	1
147/=	1
148%=	1
149<<=	1
150>>=	1
151|=	1
152&=	1
153^=	1
154**=	1
155.=	1
156