====== PHP RFC: Your Title Here ======
* Version: 1.0
* Date: 2025-09-07
* Author: Daniil Gentili, daniil.gentili@gmail.com
* Status: Draft
* Implementation: https://github.com/php/php-src/pull/19080
===== Introduction =====
This RFC enables invoking of destructor methods after a fatal error (such as an execution timeout), to match the behavior of shutdown handlers, which are also always executed after a fatal error.
===== Proposal =====
==== Examples ====
This code will always work correctly under the new RFC:
final class StatCounter {
private static self $instance;
public static function get(): self {
return self::$instance ??= new self;
}
private array $stats = [];
private function __construct() {}
public function __destruct() {
// I.e. using influx/telegraf
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');
// Stat reporting will always work on shutdown even if the following two lines are uncommented
//set_time_limit(1);
//while (1);
===== Backward Incompatible Changes =====
None.
===== Proposed PHP Version(s) =====
PHP 8.5
===== RFC Impact =====
==== To the Ecosystem ====
PHP code will be able to reliably use destructors to execute code on shutdown if needed, matching the behavior of the shutdown handler.
===== Open Issues =====
===== Voting Choices =====
* Yes
* No
===== Patches and Tests =====
https://github.com/php/php-src/pull/19080/files