-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Invoke destructors during bailout #19080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--TEST-- | ||
Invoke destructors after bailout | ||
--SKIPIF-- | ||
<?php | ||
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test is limited to one second, I don't think that counts as slow |
||
?> | ||
--FILE-- | ||
<?php | ||
|
||
final class StatCounter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems more complicated than you need <?php
class StatCounter {
public function __construct(private array $stats) {}
public function __destruct() {
echo "Sending stats: ".json_encode($this->stats)."\n";
}
}
$stats = new StatCounter(['test' => 1, 'test2' => 1]);
set_time_limit(1);
while (1); should do the same thing |
||
private static self $instance; | ||
public static function get(): self { | ||
return self::$instance ??= new self; | ||
} | ||
|
||
private array $stats = []; | ||
|
||
private function __construct() {} | ||
|
||
public function __destruct() { | ||
echo "Sending stats: ".json_encode($this->stats)."\n"; | ||
} | ||
|
||
public function inc(string $key, int $by = 1): void { | ||
$this->stats[$key] ??= 0; | ||
$this->stats[$key] += $by; | ||
} | ||
} | ||
|
||
StatCounter::get()->inc('test'); | ||
StatCounter::get()->inc('test2'); | ||
|
||
set_time_limit(1); | ||
while (1); | ||
|
||
?> | ||
--EXPECTF-- | ||
|
||
Fatal error: Maximum execution time of 1 second exceeded in %s on line %d | ||
Sending stats: {"test":1,"test2":1} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,3 +87,12 @@ Fatal error: Allowed memory size of 104857600 bytes exhausted %s on line %d | |
<!-- destroy: %s --> | ||
</Fiber::resume> | ||
</file '%s'> | ||
<!-- switching from fiber %s to %s --> | ||
<destroying '%s'> | ||
<!-- Exception: GracefulExit --> | ||
</Fiber::suspend> | ||
<!-- Exception: GracefulExit --> | ||
</{closure:%s:%d}> | ||
<!-- switching from fiber %s to %s --> | ||
<destroyed '%s'> | ||
<!-- destroy: %s --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep a trailing newline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the trailing newline