Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89336 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83169 invoked from network); 23 Nov 2015 16:17:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 16:17:44 -0000 Authentication-Results: pb1.pair.com header.from=me@daveyshafik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@daveyshafik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain daveyshafik.com from 209.85.160.179 cause and error) X-PHP-List-Original-Sender: me@daveyshafik.com X-Host-Fingerprint: 209.85.160.179 mail-yk0-f179.google.com Received: from [209.85.160.179] ([209.85.160.179:34131] helo=mail-yk0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/65-47837-62C33565 for ; Mon, 23 Nov 2015 11:17:43 -0500 Received: by ykfs79 with SMTP id s79so243975183ykf.1 for ; Mon, 23 Nov 2015 08:17:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daveyshafik-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=9qVCQoFwQV8gGzt03V1Z5WSpWgvJzWQl7ZPaCT2B2gE=; b=H3vitfa1JGJyiOccKbORyT5raY2fYpXBSrb+RrBLecz5BoWJQVcQPHEadYatPY2GQ9 wwUslUKJR4NA4a/AtNoC/BR6aUFlv0FrjS4rrJiFvYW8Z4AV7LxsU6c167RC019q6o0F EBEgWVkl0bFdf+ewx7OP3gnnzJmhz4Mpa4svGWkthrr57Mmu3o25d8FRmMRBYoC4qBvP nRQ3qAp6QmOeW5h6dVfTAoZQgmzk7ZS/DtrKE3PG19MTflqcvh9ZT5TfbWHok0wjH++x jaI5GNOHM3xK31Lc7hhZ4DtHxW/JZrzua0N0t8N4dyUXbkmaG74ri3EVMlXUefwLbGCD nIKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=9qVCQoFwQV8gGzt03V1Z5WSpWgvJzWQl7ZPaCT2B2gE=; b=IlLkrQ0K+5gI0czvOn5g5ymlOkhtJpgSn97o888ObtNDWtypdGRb84n5YEgcY3QB9w yU/R3vpn0bvQrTFVtzU3/A9SNmyMMk4+J6eACibLDThSfR91z5rCPjyKy6ZOAedBcefT kO/+TWmc61JiP7CyCv9jKGLL971+a6qBqw/lczcQ2XjtuIzBhT7Loe85Ri8iYxtUXCPn fxavWv11MrClrtmoIvGagNES7bRXVckQGmASHZkGb3MzraNSbyE2s8k86tfvsGlnsJia zQTDfgsRxf7I93+blQ2JIX1aDubYlwk5uXQ7ZoK82mWl1G2zHoYLz5nDJ75rc4fY1YI8 n8Dg== X-Gm-Message-State: ALoCoQmL4brCA5vCAVuzfhma5cddlm8Xablwtgemfpu0NeeRqjZvhXOY8R/0FROkFUDjHeC0YvP9 MIME-Version: 1.0 X-Received: by 10.13.219.6 with SMTP id d6mr7397708ywe.344.1448295459811; Mon, 23 Nov 2015 08:17:39 -0800 (PST) Sender: me@daveyshafik.com Received: by 10.13.253.130 with HTTP; Mon, 23 Nov 2015 08:17:39 -0800 (PST) In-Reply-To: <5653310E.406@gmail.com> References: <56429DAB.6010005@dasprids.de> <56455965.60101@gmail.com> <5645C1E9.8000206@php.net> <5652728F.5060201@dasprids.de> <5653310E.406@gmail.com> Date: Mon, 23 Nov 2015 11:17:39 -0500 X-Google-Sender-Auth: o-7cO7UcbRp78SFBR-1LYIp1-uU Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a114fac2869a5920525379030 Subject: Re: [PHP-DEV] Re: Resource typehint and return type From: davey@php.net (Davey Shafik) --001a114fac2869a5920525379030 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, On Mon, Nov 23, 2015 at 10:30 AM, Rowan Collins wrote: > Ben Scholzen 'DASPRiD' wrote on 23/11/2015 01:57: > >> On 13.11.2015 12:59, Bob Weinand wrote: >> >>> The alternative is replacing the resources by proper objects, without >>> methods and public properties. >>> Then we could integrate it into our object hierarchy in a very >>> lightweight way with proper typing. >>> >>> Having special syntax doesn't really improve it much... >>> >>> Bob >>> >> >> I just looked at this again, and I don't know how I could miss this for >> so long, but we already have SplFileObject. Wouldn't it make sense to le= t >> fopen() and complementary functions use that? >> >> > I believe the blocker on just rushing to convert existing resources into > objects is that there are functions like is_resource() and getttype() whi= ch > will start behaving differently. > > Functions which accept a resource as a parameter could easily be extended > to accept either a resource or an object, but anything currently returnin= g > a resource cannot be changed without declaring a breaking change. And if > you're changing fgets but not fopen, you might as well just build a new > API, which SplFileObject already has most of (for some reason, it appears > to include fputcsv but not fputs). > > Regards, > -- > Rowan Collins > [IMSoP] How is this a breaking change? The only way you can get a resource, or resource-object is from a function that currently returns a resource (e.g. imagecreate()), and you can't do anything with a resource except pass into things that expect resources. If instead they return an object, and every function that currently expects a resource now expects that kind of resource-object, it could just work=E2=80=A6 Would it be possible to create a (possibly empty, but maybe useful) interface that all of the new resource-objects implement, meaning is_resource() and gettype() can check for that going forward and return a BC result (and if necessary, leave the current implementation in there as a code path for custom extensions maybe). You could also type hint off that interface, either transparently replacing the proposed type hint, or instead of. But I would definitely prefer to see a CurlResource or ImageResource object instead of a resource type hint. Think: class CurlResource implements Resource { } function makeRequest(CurlResource $curl) { } function serializeResource(Resource $resource) { } gettype($myResource) =3D=3D 'resource' is_resource($myResource) =3D=3D true ($myResource instanceof CurlHandler) =3D=3D true The only thing I see as contentious, is actually, is_object() =E2=80=94 sho= uld that return false, maintaining BC, or true? --001a114fac2869a5920525379030--