Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89337 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85300 invoked from network); 23 Nov 2015 16:34:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Nov 2015 16:34:48 -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.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:38004] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 76/C5-47837-72043565 for ; Mon, 23 Nov 2015 11:34:47 -0500 Received: by wmec201 with SMTP id c201so113091507wme.1 for ; Mon, 23 Nov 2015 08:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=2TF6lcGI2Vo+n5SHZE8t9KiuY66Rdd+eEJ7XN068WSI=; b=g6eeoa8u+vNLKjv7DGrgz40e2NIlr5fQgXd6qAu4YOUOblc9veGZa3z5+bpvB2A98f cqStrNUrSKlGtv6zc0ezCVeNTgJugoSqdF52PprHmi0xDSgG6aYv2jucJP0P2H9t4FHe JX21LvRc9c0OhmnKqrNrCmhJk1WL2GpDILW77egKPDZnITYxOjV61dL2/Qmr02el7lMi SiklWjTYJutlbzQ5rw4KtBWglvRghv+vOwhzODHlSHMF7GynkApxgum1Q3vPTkz6f+De pDJRNw7lr6hqUUe0j2Tcxd86qbWglWqOiudewfYJueitLlsryJmXDPTHTmblBo0GS0HD c0PA== X-Received: by 10.28.229.65 with SMTP id c62mr18692606wmh.25.1448296484175; Mon, 23 Nov 2015 08:34:44 -0800 (PST) Received: from [192.168.0.147] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id c13sm13940345wmd.14.2015.11.23.08.34.43 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Nov 2015 08:34:43 -0800 (PST) To: Davey Shafik References: <56429DAB.6010005@dasprids.de> <56455965.60101@gmail.com> <5645C1E9.8000206@php.net> <5652728F.5060201@dasprids.de> <5653310E.406@gmail.com> Cc: "internals@lists.php.net" Message-ID: <56533FF7.60808@gmail.com> Date: Mon, 23 Nov 2015 16:33:59 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Re: Resource typehint and return type From: rowan.collins@gmail.com (Rowan Collins) Davey Shafik wrote on 23/11/2015 16:17: > > 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… Within those functions, it's fine, but there are a handful of "meta" functions which can tell the difference between a resource and an object, and these may be used in existing code for error handling or switching behaviour - e.g. switch ( gettype($file) ) { case 'string': // code to open a new handle break; case 'resource': // code to use the open handle break; case 'object' if ( $file instanceOf MyFileWrapperInterface ) // ... break; default: // error } > 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. This certainly helps, but you've still got to break something, because currently is_resource() and is_object() are mutually exclusive, and gettype() can only return one string, so you've got to break somebody's code somewhere. (Cue xkcd "every change breaks somebody's flow" comic; but I think the example above demonstrates that this is a non-trivial break.) > But I would definitely prefer to see a CurlResource or ImageResource > object instead of a resource type hint. Definitely agree here. > The only thing I see as contentious, is actually, is_object() — should > that return false, maintaining BC, or true? I think it would be weird not to have it return true - otherwise in 10 years time, there'd be a weird note in the manual saying "is_object($var): returns true if $var is an object, unless it is one of the following internal types..." gettype() returning 'resource' for an object would be similarly surprising. More contentious is how is_resource() should behave; assuming *all* resources are converted, it could just be deprecated anyway, I guess... Regards, -- Rowan Collins [IMSoP]