Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89355 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29396 invoked from network); 23 Nov 2015 22:10:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 22:10:35 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wm0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:35036] helo=mail-wm0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/3D-47837-9DE83565 for ; Mon, 23 Nov 2015 17:10:34 -0500 Received: by wmuu63 with SMTP id u63so73183177wmu.0 for ; Mon, 23 Nov 2015 14:10:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=szSJdmQ8o1JlBxd1fqcLnrWoKSvpVx8imgKIuGbIpU0=; b=j6y1hg9xWbyAn213nI5NL2T/INISWD24HrzkKa4xVoFzMFOZ+mm5YyVEEA6YNUh/xd iKsZtLQ0Ow6NyAO9nfZgf4X3MJHk3Cfn6zzmcsF84Nsd5GASTyB1+sJ9U1um8j7t6QoG 864mqW8n+OdVkptz7wMUlQ04KvQgBq3S+ft39ykCxQ+gKVQRno8rrUWjbXmqWJraY+jO JUMcq+bw2hDrC9FaJtqjFQ5FP32EEUl7Ai6uj3pjCvgZI3W1JwuuG4KfqRle8BSXquLt FfmD+dK04Ot8P3gd6OyPbOEJbYwu2LYD7OLJyBjz2Wrrlkcq6p+Mhmg0TeQl/3I1sbxZ pYRA== X-Received: by 10.194.185.6 with SMTP id ey6mr33358652wjc.42.1448316630502; Mon, 23 Nov 2015 14:10:30 -0800 (PST) Received: from android-c0c105534eccd9bf.default ([95.148.161.224]) by smtp.gmail.com with ESMTPSA id 200sm15225472wmn.11.2015.11.23.14.10.29 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Nov 2015 14:10:29 -0800 (PST) User-Agent: K-9 Mail for Android In-Reply-To: <56536407.9080702@dasprids.de> References: <56429DAB.6010005@dasprids.de> <56455965.60101@gmail.com> <5645C1E9.8000206@php.net> <5652728F.5060201@dasprids.de> <5653310E.406@gmail.com> <56536407.9080702@dasprids.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Mon, 23 Nov 2015 22:10:24 +0000 To: Ben Scholzen 'DASPRiD' ,internals@lists.php.net Message-ID: Subject: Re: [PHP-DEV] Re: Resource typehint and return type From: rowan.collins@gmail.com (Rowan Collins) On 23 November 2015 19:07:51 GMT, Ben Scholzen 'DASPRiD' 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]