Am 14.03.2015 um 18:34 schrieb Crypto Compress: > >>>> So I do not see the need of a explicit class deconstructor, because the >>>> language should already react correctly on this issues as I can see so >>>> far >>> The language cannot know the order of dependencies and how to destruct >>> them. >> A dependcy between destructors of instances, which the language have to >> know by itself that sounds horrific indeed. >> >> If one instance has destruction dependcies to other instances, you >> should have used any kind of linking pattern between this instances so >> the __destruct of the first instance destructed can handle the >> destruction dependcies. At the moment I cannot think about any use case, >> where this should be done another way. Maybe you have a concret example >> for me, so I can think about this? > > a) Implicit order of dependencies: > Logger should be the last destructed > DatabaseLogger before FileLogger before error_log-Logger... >
Okay the Implicit order for class unload should be safe, if you use the Logger classes inside class A and class B, PHP should unload the class Logger as last one after A and B. The unload order of DatabaseLogger before FileLogger is a internal of the Logger Instances as Logger itself is a singleton Factory: For example: class LogAdapter { private static $instances = []; public static getLoggerInstance($classname) { if (!array_key_exists($classname, self::$instances)) { self::$instances[$classname] = new Logger($classname); } return self::$instances[$classname]; } } class Logger() { ... public __destruct() { //Unload whatever you need. } } > b) How to destruct: > Write "Bye!" before closing socket. > > To manage a socket connection is not a typical use case for a "global" static class context because normal use case of a Socket class is to manage different Sockets. So this is typically a instance pattern to use, where the __destruct() can say bye. >> On destruction/unload of a class the language should be able to unset >> static properties in random order for this reason, without any need of a >> class destructor?! > > Reverse creation order. The random was just meant as placeholder for the fact that for static properties it should not matter in which order they are unset by the language. Can be reverse creation order or something else. Regards -- DerOetzi -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php