File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Invoke destructors after bailout
3+ --SKIPIF--
4+ <?php
5+ if (getenv ("SKIP_SLOW_TESTS " )) die ("skip slow test " );
6+ ?>
7+ --FILE--
8+ <?php
9+
10+ final class StatCounter {
11+ private static self $ instance ;
12+ public static function get (): self {
13+ return self ::$ instance ??= new self ;
14+ }
15+
16+ private array $ stats = [];
17+
18+ private function __construct () {}
19+
20+ public function __destruct () {
21+ echo "Sending stats: " .json_encode ($ this ->stats )."\n" ;
22+ exit (0 );
23+ }
24+
25+ public function inc (string $ key , int $ by = 1 ): void {
26+ $ this ->stats [$ key ] ??= 0 ;
27+ $ this ->stats [$ key ] += $ by ;
28+ }
29+ }
30+
31+ StatCounter::get ()->inc ('test ' );
32+ StatCounter::get ()->inc ('test2 ' );
33+
34+ set_time_limit (1 );
35+ while (1 );
36+
37+ ?>
38+ --EXPECTF--
39+
40+ Fatal error: Maximum execution time of 1 second exceeded in %s on line %d
41+ Sending stats: {"test":1,"test2":1}
You can’t perform that action at this time.
0 commit comments