Re: Re: Resource typehint and return type

From: Date: Mon, 23 Nov 2015 22:10:24 +0000
Subject: Re: Re: Resource typehint and return type
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-89355@lists.php.net to get a copy of this message
On 23 November 2015 19:07:51 GMT, Ben Scholzen 'DASPRiD' <mail@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]

« previous php.internals (#89355) next »