Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86197 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63228 invoked from network); 13 May 2015 17:30:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 May 2015 17:30:10 -0000 Received: from [127.0.0.1] ([127.0.0.1:20812]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id CF/A2-42752-22A83555 for ; Wed, 13 May 2015 13:30:10 -0400 Authentication-Results: pb1.pair.com smtp.mail=guiwoda@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=guiwoda@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.169 as permitted sender) X-PHP-List-Original-Sender: guiwoda@gmail.com X-Host-Fingerprint: 209.85.213.169 mail-ig0-f169.google.com Received: from [209.85.213.169] ([209.85.213.169:37662] helo=mail-ig0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/A2-42752-AD683555 for ; Wed, 13 May 2015 13:16:11 -0400 Received: by igbsb11 with SMTP id sb11so51082296igb.0 for ; Wed, 13 May 2015 10:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=oxnguFcgqMrdPGHeE62LVBkxKoQ89EgWN4VcoW0n4YU=; b=uIgE227cZPzMgljNZTQIc6XZg5aqkfmbj2aOyumgcy5skFQZHa7broGxfmclfPrAid ywXILnXSQkcR7BdX5lxUv694qzmtDw02jd2VEBuby0GQmGEB+WAc1GcHQ8MBhgKsCZli /Sl4wE6fYUKVmEgsZk2XD2AU1p1tRu4YQwEFfdx6p4UhcspysefVF6foCuYyFxQAAcmv lk/dCiYGbrLM/24R5pOenHip9wQgztcJiCbD+Q/yS8aMSfmlj34aJ1iJSc36UDASMh6h xxoXjvQPaeegmNApOLOUAPc6SK6BhPjSdoVZTh6ntUXIx16uZQAt6r0QHI5PAtU97DiV R4MQ== X-Received: by 10.107.33.21 with SMTP id h21mr28593138ioh.1.1431537368360; Wed, 13 May 2015 10:16:08 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 13 May 2015 17:16:07 +0000 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a1140408c52ec370515f9c47e Subject: Proposal: interfaces for object to scalar type casting From: guiwoda@gmail.com (Guido Contreras Woda) --001a1140408c52ec370515f9c47e Content-Type: text/plain; charset=UTF-8 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 Cheers! --001a1140408c52ec370515f9c47e--