Req #70248 [Opn->Csd]: lighweight function to detect that shutdown has started

From: Date: Wed, 12 Aug 2015 14:49:32 +0000
Subject: Req #70248 [Opn->Csd]: lighweight function to detect that shutdown has started
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195156@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70248&edit=1 ID: 70248 User updated by: raat1979 at gmail dot com Reported by: raat1979 at gmail dot com Summary: lighweight function to detect that shutdown has started -Status: Open +Status: Closed Type: Feature/Change Request Package: PHP options/info functions Operating System: Irellevant PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I forgot the line "register_shutdown_function(array('utilityClass', 'destructStatic'));" after "self::$_constructed = null;" in the test script constructStatic, will issue a new one later Previous Comments: ------------------------------------------------------------------------ [2015-08-12 14:20:27] raat1979 at gmail dot com Description: ------------ At the moment the only way (i know of) to determine if a function is called during shutdown by means of a register_shutdown function is to do a debug_backtrace which is a resource heavy function or to enable output buffering and check for PHP_OUTPUT_HANDLER_END which also uses resources for the output buffering It would preferable to have a way to check if the script is in shutdown mode using a more lightweight function. I took an implementation of a static constructor/destructor for a utility class as example but it would be usable for many other purposes https://wiki.php.net/rfc/static_class_constructor considers the implementation of static constructors but also does not see the need for destructors. I agree that there is no need to create a standard implementation for a static destructor. However should you need it it would be really practical to detect that shutdown has started without allocating a lot of resources. Test script: --------------- abstract class utilityClass{ private static $_constructed = false; //seal the constructor to prevent creation even from subclasses final private function __construct(){} final public static function constructStatic(){ if(self::$_constructed!==false) return; self::$_constructed = null; /* do construction here */ self::$_constructed = true; } final public static function destructStatic(){ if(self::$_constructed!==true) return; // I REALLY DON'T LIKE THE BELOW debug_backtrace call if(count(($bt=debug_backtrace()))>1 || isset($bt[0]['file']) || isset($bt[0]['line'])) return; $_constructed = null; /* do destruction here */ $_constructed = false; } }utilityClass::constructStatic(); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70248&edit=1

« previous php.bugs (#195156) next »