Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86198 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66360 invoked from network); 13 May 2015 17:44:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 May 2015 17:44:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; 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: derokorian@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wg0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:33263] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/03-42752-38D83555 for ; Wed, 13 May 2015 13:44:36 -0400 Received: by wgin8 with SMTP id n8so51355327wgi.0 for ; Wed, 13 May 2015 10:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=1+nQ5Xn1GAxLzdNem8kf/ViNf5bwH1qO5FDMBjCtw5Q=; b=fDhJ6LNRTGsLzHhnsimUATg+vl4q3v8X6NuWgfKsrk4iHZhPRbZ+FS3qAmJ1EzAIv4 hCXoMx9vKMH0c06ifL7m7Pe53ms3yPMwO2gfT42X8OrUnbQjLKVlVxLOCFyV3SP6iH3i +zcIriBT9Ty0wcNdjQfQ8jI+28HosC64eqoAxkIGiPRJRMuP+O6dPkA54G+3W5jwhrBY 9DDPVew90a3UbVE4VKpyD25np7wjDk3WMNjPLNh7ejqZtLoy0uOTxTsyvQEyFOsPh9D5 smrFyQZVQZWyS48n4Yp1B4Go7PQHpcl518sd6/FZ5Z/aIEhWB8T3Ezjk0SzYqSageffV 8aGw== MIME-Version: 1.0 X-Received: by 10.180.107.38 with SMTP id gz6mr16384286wib.63.1431539072719; Wed, 13 May 2015 10:44:32 -0700 (PDT) Received: by 10.28.7.196 with HTTP; Wed, 13 May 2015 10:44:32 -0700 (PDT) In-Reply-To: References: Date: Wed, 13 May 2015 11:44:32 -0600 Message-ID: To: Guido Contreras Woda Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f2356ade95dc60515fa2938 Subject: Re: [PHP-DEV] Proposal: interfaces for object to scalar type casting From: derokorian@gmail.com (Ryan Pallas) --e89a8f2356ade95dc60515fa2938 Content-Type: text/plain; charset=UTF-8 On Wed, May 13, 2015 at 11:16 AM, Guido Contreras Woda wrote: > Hello everyone! > > Multiple frameworks and libraries define interfaces or objects that wrap > around some scalar value and add behavior, the most common case being > arrays and Collection / Hash[Set|List] objects. Although this objects > benefit from the possibility of having behavior themselves, sometimes the > implementation is outside our project scope (an external dependency) and > interaction between this object and other blocks of code that expect scalar > types usually needs to be controlled by the user, which adds the necessity > for adapters or some sort of mediator. > > Now that we have the ability to hint return types, a common interface could > be built that, given an object that implements it, lets userland code use > this object as if it were the scalar type it is wrapping. Unboxing the > object is pretty easy, and I wouldn't go as far as proposing interfaces for > rebuilding the object itself (not now, at least). > > So, what do you think of a set of interfaces that allow userland objects to > be used as scalar types? > > Some simple examples in PHP here: > https://gist.github.com/guiwoda/5d16c8fb97d29e476d20 > > I like the idea of supporting more __toType methods than just __toString. It would certainly make certain things in life a bit easier to manage. For now, I know I've abused __toString() and done things like (int)(string)$obj to get the Int value out of it. > > Cheers! > --e89a8f2356ade95dc60515fa2938--