On 23 November 2015 19:07:51 GMT, Ben Scholzen 'DASPRiD' <m...@dasprids.de> wrote: >There's another blocker: the SplFileObject currently has no fclose() >method, which should definitely be implemented. Currently it relies on >being destroyed to close the internal resource. In case of cross >references, there's no way to explicitly close the file handle.
Using reference counting and destructors as a mechanism for releasing resources is a very common OO pattern (sometimes referred to as "RAII"), and also used elsewhere in PHP, e.g. PDO. It means that anywhere you have a reference to the object, you can actually use it, rather than having to check if it's been closed elsewhere, and saves the need for try..finally blocks in many places. If you do want a weak reference, you can wrap it in a delegating container, with the "close and start throwing exceptions" behaviour you're after: just have a private member for the real resource, and pass through method calls only when it is not null. Also note that circular references are not a big problem, as PHP has had a dedicated garbage collector built in for some time now, and you can normally limit their use with careful design. Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php